To rename Random Excel filename to a standard filename

Good day Automation Experts,
My robot downloaded an Excel file everyday with file name: Report_ddmmyy.xlsx
I need to use UI Path to go this specific folder and rename it to: Report.xlsx, move to another folder and delete it from the original folder.

Appreciate your help and advice. Prefer to have detail steps to guide, as I am very new to UiPath.
Thank you very much.

Hi @Woonhan_Yap, welcome to the Community.

You can do this in 2 ways:

  1. Either you can directly mention the location of the file to which you need to save the file.

  2. You can use the combination of these activities to move the file from the source location to a destination location.

image

Hope this helps,
Best Regards.

1 Like

Thank you @arjunshenoy for your reply.
For the Move Activity, I cannot determine the source filename, because the filename will change everyday according to different dates. Hence, is there a way to use wildcard like “**.xlsx”?

Thank you and cheers~

@Woonhan_Yap Hi Folk,
You can you simply move activity with two ways.
1)
Use Move File activity to rename file with in folder by putting Original full path in from and same folder path with new file name in To block. This will rename your file with in folder.

After that you can use again move file activity to move it in new folder.

Now use delete file activity to delete file from old folder.

In this method use move file activity to move file directly from one path to another path with new name.
There is no need to delete file from old path.

@Woonhan_Yap

In the case of the dynamic file name, you can design it like this:

"Report_"+Now.ToString("ddmmyy")+".xlsx"

This will give you the file name based on the current date.

Edit - The file names can be dynamic like this:

image

Hope this helps,
Best Regards.

1 Like

Thank you very much @arjunshenoy That’s very helpful :slight_smile:

However, I tried to put in the command to determine dynamic filename as below: (Using “Move File” activity, in the “From” column)
“C:\Users\Downloads"Report_”+Now.ToString(“yyyymmdd”)+“.xlsx”

and I have got below error…

Argument ‘Path’: Compiler error encountered processing expression ““C:\Users\Downloads"Report_”+Now.ToString(“yyyymmdd”)+”.xlsx"".
(1): error BC30027: ‘End Function’ expected,
(2): error BC30198: ‘)’ expected.
(2): error BC30648: String constants must end with a double quote.

Hope to get your support and suggestion.
Thank you very much in advance

@Woonhan_Yap

I can see there is a ‘\’ missing in the above address. Can you please fix it & try the same again?

The updated address would be this:

newAddress = Path.Combine("C:\Users\Downloads","Report_”+Now.ToString(“yyyyMMdd”)+“.xlsx”)

image

Hope this helps,
Best Regards.

1 Like

Good day @arjunshenoy ~ Yes, it work and resolved the error with below code:
“C:\Users\Downloads"+“Report_”+Now.ToString(“yyyymmdd”)+”.xlsx"

However, every time I ran, it gave me different results on the day (dd)

The results are different every time I ran:
1st attempt: Report_20230911.xlsx
2nd attempt: Report_20232911.xlsx
3rd attempt: Report_20233211.xlsx

But the original file generated was: Report_20230511.xlsx
Do you have any idea, why is this happening? :wink:

Thank you very much in advance.

@Woonhan_Yap

My bad. Please try the upper case for month representation. Like this:

Now.ToString(“yyyyMMdd”)

Best Regards.

1 Like

WOW! It worked perfectly now! Thank you sooooo much @arjunshenoy

1 Like

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