Ever wondered how you can create filenames by cycle.
Well, I did, because I needed it. And I came up with something that works and because once i forgot it, I decided this time to put it here. At least, I won't forget again :) If you have a better way to do it, please, say so.
The idea:
>A:=`/home/Data/file_`; B:=`.txt`;
>for i from 1 to 3 do C:=cat(A,i,B); writedata(`C`,[i],integer);od;
As simple as it is, it took me some time to figure it out.
And it's very useful if you have a cycle with a procedure that writes out long love messages in terminal, but you want to put it in command mode and read the output from a file later.
The above will write the meaningful value of i in a file with the corresponding name: /home/Data/file_i.txt. The use of A,B and C is optional, of course, but this way it looks better to me. The short version is:
>for i from 1 to 3 do writedata(cat("/home/Data/file_",i,".txt"),[i],integer);od;
Comments
Very nice!
By the way, if you want to keep such code portable across platforms, it's helpful to replace the fixed (static) path to your directory with cat(kernelopts(homedir),"/Data"). This feature was introduced in Maple 9.5.
Thanks
Yup, I want that :) Especially since I prepare the files on one pc and then run them on another. Thanks for letting me know of this option.