Priyanka
Priyanka

Reputation: 581

Dymola mos script: get current directory

In a mos script, I want to save the current directory (i.e. the directory where the mos script is) to a string variable. In a second step, I want to open a library that is located in a directory net to the mos file.

I tried it like this:

myCWD = Modelica.Utilities.System.getWorkDirectory();

but this will always have the value C:\USERNAME\Documents\Dymola.

Is there a way to get the path of the mos file itself, from within the mos script? Or are there better ways to use relative paths, or construct absolute paths from a relative path (but always relative to the mos file)?

Upvotes: 2

Views: 690

Answers (1)

marco
marco

Reputation: 6655

cdreturns Dymolas working directory, so it works as expected. I don't know how to solve your problem with mos scripts, but in a Modelica function the Dymola built in function classDirectory() does what you want.

Here is a minimal example:

function myScript
algorithm 
  Modelica.Utilities.Streams.print(classDirectory());
end myScript;

Note that in Dymola functions can replace mos scripts in most cases. Usually you can simply copy your mos script content to the algorithm section of a function and call the function.

Upvotes: 2

Related Questions