Best practice for cross-platform file system manipulations in GAMS

后端 未结 1 396
被撕碎了的回忆
被撕碎了的回忆 2020-12-21 17:20

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 mani

1条回答
  •  有刺的猬
    2020-12-21 17:59

    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.

    0 讨论(0)
提交回复
热议问题