User Tools

Site Tools


gams:dynamic_renaming_of_put-files

Dynamic renaming of put-files

$title example for renaming put files
file test / test.txt /;
put test;
set i / i01*i10 /;

loop(i,
* this will flush and close the current put file and rename it
* to any name written in the second line of the put statement
   put_utilities 'ren' / 'test.':0 i.tl:0  ;
   put 'this should be ' i.tl
  );

Using another put_utility this also works with directory names. Below is an extended version of the example, which generates the subdirectory during the loop as well.

file test / test.txt /;
put test;
set i / i01*i10 /;

loop(i,
* generate the directories
     put_utilities 'exec' / 'mkdir ' 'test-':0 i.tl:0;

* this will flush and close the current put file and rename it
* to any name written in the second line of the put statement
     put_utilities 'ren' / 'test-':0 i.tl:0 '/test-':0 i.tl:0 '.txt':0 ;
     put 'this should be ' i.tl
   );
gams/dynamic_renaming_of_put-files.txt · Last modified: 2007/08/09 12:25 (external edit)