Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
433 views
in Technique[技术] by (71.8m points)

filesystems - Best practice for cross-platform file system manipulations in GAMS

I would like to manipulate the file system from some GAMS code. I am coming to this project mid-stream, and as a GAMS newbie, but am used to writing cross-platform file manipulations in other languages. It would be good for this code to be cross-platform Linux and Windows. Right now there is a commented-out line

*$call 'mkdir "%runfolder%"'

that I would like to un-comment (enable), however, I am having a hard time finding documentation on whether this would work cross-platform (I suspect not), and if not, how I could do this in a cross-platform way.

How can I manipulate the file system in a way that is guaranteed to work cross-platform?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try using a global variable that defines the file separator. You can do this by querying the system.filesys system variable and setting the value accordingly. Such as:

* ----- Platform Specific Adjustments
* Setup the file separator to use for relative pathnames 
$iftheni %system.filesys% == DOS $setglobal filesep ""
$elseifi %system.filesys% == MS95 $setglobal filesep ""
$elseifi %system.filesys% == MSNT $setglobal filesep ""
$else $setglobal filesep "/"
$endif

Then you can use this when you need to specify paths, as in:

* ----- Set data and output directories
* By default look for data in the sibling directory "data"
$if NOT set data_dir    $setglobal data_dir ..%filesep%data%filesep%   

Note that GAMS doesn't let you indent $if and related directives.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...