Based on file or directory existence

Top  Previous  Next

Conditionals may be placed in the GAMS code that do particular things only if a named file or  directory exists or conversely with the use of the not command if it does not exist.  Such commands are of the form

 

$If exist fullfilename gamsstatement

$If not exist fullfilename gamsstatement.

$If dexist fulldirectoryname gamsstatement

$If not dexist fulldirectoryname gamsstatement.

 

where the first of the four syntax alternatives yields a true conditional if the file exists and the second if it does not.  Similarly the third of the four syntax alternatives yields a true conditional if the directory exists and the last if it does not

Examples:

$If exist c:\myfile $call "copy "c:\myfile con"

$If exist fileexist.gms $call "copy fileexist.gms con"

$If dexist c:\ $call "copy "c:\myfile con" c:\

 

 

These statements also show one can include operating system commands as discussed below.