Macro to rename files from FILE1 to 1FILE

I have a macro to split channel but the result of the macro shows me my FILE ending with number but I need my FILE to start with a number so I can use another macro.
This is the macro

macro “split” {

path = getDirectory(“Choose a Directory”);
list = getFileList(path);
length = list.length;

File.makeDirectory(path + “Imaging/”);

//Split for analysis

for (i=0; i<length; i++) {

img = File.nameWithoutExtension();

run(“Split Channels”);
selectWindow(“C3-” + list[ i ]);
saveAs(“Tiff”, path + “Imaging/Dem” + i);
selectWindow(“C2-” + list[ i ]);
saveAs(“Tiff”, path + “Imaging/Aem” + i);
selectWindow(“C1-” + list[ i ]);
saveAs(“Tiff”, path + “Imaging/DeX” + i);
selectWindow(“C4-”+ list[ i ]);
run(“Close All”);

How Can I add a + i parameter before the name so I can have my file as 1File and not File1 when I save them?

Thank in advance for any help

How about
saveAs(“Tiff”, path + IJ.pad(i,2)+“Imaging/Dem”);
The pad is to have more than 9 images line up nicely (filenames 01File…99File)

Thank you for your help. I tried in the macro but I got a error message.Please,see below
|Error:||Undefined variable in line 21:|
saveAs ( <“Tiff”> , path + IJ . pad ( i , 2 ) + “Imaging/Dem“);”

I do not know why “Tiff” is causing the problem.
Thanks in advance for any help

I manage to fix it a little bit deleting the "imaging/ part of the saveas
saveAs(“Tiff”, path + IJ.pad(i,2)+“Dem”);
but the problem is that the files are not saved in the output folder “Imaging”

Tiff caused problems because of typographic problems. You probably copied the text and got fancy quotes rather than the ‘normal’ quotes (look closely, you will notice upside down double quotes, where plain quotes are necessary).

To put files in a subfolder, you first need to make sure the subfolder exists (test with File.exists(path+“Imaging”)), or create that folder first. (Capitals mixed with lower case is a recipe for disaster BTW) .Then you have to make sure the last character of the path is a directory separator. I usually do that by getting the file path (that is path including the file name), taking off the file name and the remainder of the path string then automatically has the proper character which is the directory separator.

Then you can say
which should result in filenames like


Thank you very much eljonco, It works Perfectly
Kind Regards