A batch that creates csv files with different name

Hi there!

I would like to create a batch that explores every day a formula and saves it as a CSV File. Is there any possibility to change automatically the name of the file? For example, Exploration_System1_20020118

I only see the option where it overwrites the CSV file everytime.

Thanks and regards,

Dani

You can just create a Windows BATCH (.bat) file that will issue RENAME command from the "constant" file name to the name of your choice (you could use commands inside .bat file to create date string).

Really, for all your programming questions USE GOOGLE. Google has pretty much all answers to such typical questions.
If you searched for "windows batch rename with date":

https://www.google.com/search?q=windows+batch+rename+with+date

the VERY FIRST hit is this:

1 Like

Thanks for the tip. I always write Amibroker and didn't find any solution!

Thanks a lot! :smile:

Anorther solution consists in using an AFL script to rename your file. There are several ways, for instance read Tomasz' solution using JScript

It's easy to add date as suffix:

fso = CreateObject("Scripting.FileSystemObject");
path = "C:\\Users\\Public\\Documents\\";
filename = "Exploration_System1";
// if (ParamTrigger("Rename", "[ CLICK ]"))
fso.MoveFile( path + filename, path + filename + "_20" + (Now(3)-1000000));

Actually as your file is a csv file (text type) you can also copy it line after line and delete the original using afl functions (this avoids the warning)

src = fopen(path+filename, "r");
dest = fopen(path+filename+ "_20" + (Now(3)-1000000), "w");

if (src && dest) {
	while(!feof(src)) {
		fputs(fgets(src), dest);
	}
	fclose(dest);
	fclose(src);
	fdelete(path+filename);
} else {
	if (src) fclose(src);
	if (dest) fclose(dest);
}
2 Likes

Actually to copy file you just need single line of ShellExecute.

path = "C:\\Users\\Public\\Documents\\";
filename = "Exploration_System1";
src = path+filename+".csv";
dest = path+filename+"_copy.csv";

if ( ParamTrigger("Copy file", "Click here"))
    ShellExecute("cmd", "/c copy \"" +src+ "\" \"" +dest+ "\"", "", 0);

Also for moving file you do not need OLE but just single ShellExceute.

path = "C:\\Users\\Public\\Documents\\";
filename = "Exploration_System1";
src = path+filename+".csv";
dest = "C:\\";

if ( ParamTrigger("Move file", "Click here"))
    ShellExecute("cmd", "/c move \"" +src+ "\" \"" +dest+ "\"", "", 0);
3 Likes

ShellExecute() based solutions were already listed in the thread I linked to, so I didn't mention them. By the way as noted there it can cause problems depending on usage (read the 1st post). In that case the 2 solutions I wrote here should work. Thanks for repeating them there anyway.

2 Likes

Wrong, I rather repeated from my 2017 post here just using different command.

As for problem... I have not reproduced it.

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.