Q: I would like to ask you if there is a way to include a file by just stating a part of its name. For example, I want to include test1.txt and I'm wondering if instead of stating:
I could use something like
GAMS does not allow you to specify wild cards in filenames. There is however a way around it using the wild cards of the shell:
$echon '$setglobal fname ' > setfname.gms $if %system.filesys% == UNIX $call ls test?.txt | head -n 1 >> setfname.gms $if not %system.filesys% == UNIX $call dir /B test?.txt | head -n 1 >> setfname.gms $include setfname $log *** including %fname% $include %fname%
dir (Windows) or
ls (Unix) is used to produce a list of files that match your file pattern. Since there could be multiple files, we use the Posix utility head to get the first file in the list. The program head is part of any Unix OS and is included in the GAMS Windows system (subdirectory gbin) with recent GAMS distributions, so this little program should run on all platforms.