Best practice for cross-platform file system manipulations in GAMS

和自甴很熟 提交于 2019-11-29 16:34:58

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!