How to rename the files just moved?

Hi, I am building a workflow to automate the process that I need to do everyday which is moving a bunch of reports are updated daily. I have done the move files part but struggling with the renaming them. I want to rename the as below logic : “movedfiles_20220508” → “movedfiles” . How do I apply the logic and apply it to all file I need at once ?

Hey,

welcome to our community, you can save the download file path, and then use an rename file activity, pass the path and the new name

Regards!

1 Like

Hello @Joseph_43 ,

In the move File activity itself you can change the name. For example you are trying to copy the files from c drive to D drive and the file name is UiPath.txt. SO the file path will be C:\UiPath.txt
If you want move that to D drive and name it as UiPathAutomation.txt, then in the Destination value give as below, D:\UiPathAutomation.txt

image

1 Like

Hi,

If you want to remove “_yyyyMMdd” in all the target files, like “yourFile_20220509.xlsx” to “yourFile.xlsx”, the following will work.

System.Text.RegularExpressions.Regex.Replace(System.IO.Path.GetFileNameWithoutExtension(CurrentFile.Name),"_\d+$","")

Regards,

2 Likes

Thanks! your demo seems working but only one thing : I tried to run twice beucase I want to simuate the situation that I shall need to do this every day then the error pops up with this message:

Rename File: Cannot create a file when that file already exists.
Can I fix the issue here or I need to delete the existing file first then run the flow

Hi,

If there already exists same named file, RenameFile activity cannot rename to it . So you need to remove, move to other folder or rename it in advance then run.
Or add logic to avoid rename to the same name like -1 , -2…

Regards,

1 Like

Thanks all, my question here is fully solved. Hope you all getting better with UIPATH !

1 Like

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