Reputation: 193
What is the best way to handle directory across windows and Unix based file systems in Rascal MPL, such that user of the Rascal project can read and generate files in those OS appropriately?
Upvotes: 1
Views: 61
Reputation: 6696
It depends on the situation.
home:///
or tmp:///
or project://<name>
, or use IO::findResources
.
+
to get to the children: path + "myFile.rsc"
will take care of the proper escaping, encoding and add the path separator /
myPath.ls
to get a list of entries in a folder. Also in util::FileSystem
there are more operations that work on any location to get an overview of a filesystem.remove
, lastModidied
, etc. etc.|file:///C:Program%20Files/|
as a literal in your analysis results or in your intermediate M3
models. In this case, all your downstream analysis will work correctly, except that jumping to the code will not work properly (since the code on your Mac doesn't have that folder.
clair
this does not work. They always produce file:///
URIs.IO::relativize
is elemental here. It will give you the postfix unique path name by removing the given prefix, if it fits. So relativize(|file:///C:Program%20Files|, |file:///C:Program%20Files/Hello.txt|)
produces relative:///Hello.txt
. Then you can add the relative path to the new path: newPath + relative.path
. Such a transformation is lineair in the size of the model and could take a few seconds! Typically you would visit { case loc l => ...}
in a few lines of code that write all locations where necessary.|file:///C:Program%20Files/Hello.txt|
, send it to the Windows machine and there when used by writeFile
it would have the desired effect.In short:
Upvotes: 2