Changing folder names according to the data stored in excel

Hi, I have a big amount of files and I need to change their names according to the data stored in an excel file. How do I do that? Changing goes on like this: the first file is titled as 5555 and the second is 6666, their new version will be FILE01015555 and FILE 01026666. It will keep changing as “FILE0103. FILE0104 …” until all the files are renamed.

This will do the trick. I’ve set the parameter to the workflow to the input directory you’re reading from. (841,0 Ko)


Hi that was so helpfull thank you, however i also want to understand the logic behind this, you access the input folder with in_FileSource can you explain how you access input folder?

Also if i want to take file names in excell how can i do that?

Sure thing.

1.) Assign - FileArr: Directory.GetFiles returns an array of strings which are full paths to the files in the specified input directory. There are options to get all files in subdirectories and search on a match string, but we only need the top-level files in this case.

2.) File = Path.GetFileName: Here we’re getting only the name of the file without the full path. This is necessary so we can use that name in the new name of the file.

3.) Move File - Rename: Whenever you use the Move File activity with Overwrite enabled, it will rename the file if you’re placing it in the same directory. The input is the full path of the file for the From parameter, and the new filename for the To parameter.
* Path.Combine Takes strings as arguments and separates the strings using the system directory level delimiter (in our case the \ symbol).
* String.Format The first parameter is a string, and any {n} where n is an integer refers to the position of the following arguments. So the next argument to String.Format will be placed at position {0}, the second is placed at {1}, etc.
* FileIx + 1 If you look under the output parameters of the For Each activity, you’ll see that it can output the current index. We use this to help us generate the file name. Since it starts at 0, we add 1 to the index.
* .ToString("D2") The D2 in this string conversion indicates that the format of the value is an integer occupying two characters. In other words, this will handle leading zeroes as follows: (…07, 08, 09, 10).

1 Like

Thank you for helping me to understand you are the best. Now i’m trying to change their names according to the data stored in an excel file but I couldn’t do it. I was thinking the use 1 more for each row loop inside the your loop but its giving errors. how am i supposed to do it?

Data stored in Excel files is best read using the Read Range activity and iterating over the output datatable rows using the For Each Row activity.

1 Like

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