I am trying to rename an excel file starting with a certain number, and renaming it using “Copy file”.
E.g.
The path is: C:\Users\dopn\OneDrive\Current Projects\ABC\Admin\9385_2021_05.xlsx and I am trying to change the excel file starting with “9385” when its moved to the folder. The dates behind 9385 is dynamic. So the final output should be a file titled “ABC MMM yyyy Payroll”
Currently in copy file, here’s what I have:
From: “C:\Users\dopn\OneDrive\Current Projects\ABC\Admin"+“9385”+”*“+“xlsx”
To: “C:\Users\dopn\OneDrive\Current Projects\ABC\Admin"+Filename+”.xlsx”
I have assigned Filename=“ABC”+DateTime.Now.ToString(“MMM yyyy”)+" Payroll"
I suspect there is something incorrect with the “*” in my From folder, but I don’t know how to resolve this.
This should be “C:\Users\dopn\OneDrive\Current Projects\ABC\Admin\9385*” unless you have more than one file starting with 9385 in which case you will need to loop through all.
To: “C:\Users\dopn\OneDrive\Current Projects\ABC\Admin”+Filename+“.xlsx”
Should be “C:\Users\dopn\OneDrive\Current Projects\ABC\Admin\”+Filename+“.xlsx” unless the backslash is already in your filename. I usually add the .xlsx to the filename variable so all you need to do is "path" + Filename
Thanks Prasath17. So if I want to rename the file name starting with 9385, can you share how best I can enter the From field? The number 9385 in the file name is fixed, followed by the dates, e.g. 9385_2021_05.xlsx and I want to change this to “ABC MMM yyyy Payroll”