Hello everyone. I have the following problem. I have 1000 files that need to be renamed. The files currently have the following format: ‘Last Name, First Name - Test1.pdf’ and ‘Last Name, First Name - Test2.pdf’ . Now, a number should be added in front of the name. This number must be taken from Excel . In Excel, there are the columns ‘Number’ , ‘Name’ , and ‘First Name’ . The new file name should then look like this: ‘Number - Last Name, First Name - Test1.pdf’ / ‘Number - Last Name, First Name - Test2.pdf’ . I tried to read the 3 variables with a ‘For Each Excel Row’ and then query with a ‘For Each File in Folder’ : if ‘CurrentFile.ToString’ = ‘Last Name + “, " + First Name + " - Test1.pdf”’ , then ‘Message Box “Success”’ , but unfortunately, that didn’t work. Do you have solutions?
Hi @lucas.vinke
Use for each loop to get all the files in a folder. Apply your if condition “item.tostring=LastName”.
Then use rename file activity and pass the variables of excel data as per you required the name of your file
Flow:
ExcelData = Read Range into DataTable
For Each Row in ExcelData
LastName = Row(“Last Name”).ToString
FirstName = Row(“First Name”).ToString
Number = Row(“Number”).ToString
SearchPattern1 = LastName + “, " + FirstName + " - Test1.pdf”
SearchPattern2 = LastName + “, " + FirstName + " - Test2.pdf”
Files = Directory.GetFiles(FolderPath)
For Each File in Files
FileName = Path.GetFileName(File)
If FileName.Equals(SearchPattern1) Or FileName.Equals(SearchPattern2)
NewFileName = Number + " - " + FileName
Move File (From: File, To: Path.Combine(FolderPath, NewFileName))
End If
Next
Next
Note:
Read the Excel Data
Iterate Over Excel Rows
Find and Rename Files :
Welcome to the community
In the filter option you can directly give the combination you need instead of if condition again
Even if you use if currentfile.ToString…will giv eht fullpth
You need to use currentfile.name to get the name
Cheers
Okay, I’ll try to describe the problem again. My Excel table is structured as follows:
| Number | Last Name | First Name |
|---|---|---|
| 1234 | Max | Mustermann |
| 2345 | Muster | Frau |
| 5678 | Test | Benutzer |
When I use the ‘For Each File in Folder’ activity, it only works for the first record. After that, it processes the second file, but it doesn’t advance to the next record in the Excel table. (Loop For Each File in Folder)
The new format for each file is: ‘Max, Mustermann - Test1.pdf’ => ‘1234 - Max, Mustermann - Test1.pdf’
Each file has a different name in the folder due to the various names across 1000 files."
I hope this helps! If you need further assistance, feel free to ask. ![]()
Only works for the first person. After that its a new file name but with the old data table assign
So it cant be renamed.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
