Renaming a Dynamic Excel File Name

I have an excel file with the name format “20200410_ABC_IU-Investors.xls”. Here, the highlighted part is dynamic and shows the date on which the file was downloaded. I want to rename the file completely to something like “ABCBuyers.xls”.
I have tried the rename activity but it stops working once the date changes.

I would really appreciate some help. Thank you.

@Ana_Shrivastav Can you Show us Screenshots of your Workflows as to what you are currently doing?

@Ana_Shrivastav When Downloading does it Directly Download the File, or does it ask for a Save As Option? You an rename the file when it is being downloaded


It directly goes to the Downloads folder(it is a database generated file), so it doesn’t give an option for Save As while downloading. I can’t rename it until and unless it is present in the Downloads folder.

I want to build a flow that renames the file every day when a new file is downloaded with a new date.

@Ana_Shrivastav Can you use this Expression to get the Latest File added to the Downloads Path :
Directory.GetFiles(“yourFolderPath”).OrderByDescending(Function(x)CDate(new System.IO.FileInfo(x).CreatedDate)).ToArray(0)

1 Like

Hi @supermanPunch,

The flow works when the file name is the same as mentioned in the File Path. The moment file name changes i.e the date in it changes, the flow stops working. I tried using the illegal character in place of date while declaring the file path, that also didn’t work.

I want to build a flow that renames the file every day when a new file is downloaded with a new date.

I might be making a mistake as am new to Uipath and my knowledge is limited.

@Ana_Shrivastav Have you used the Expression I have Provided above to get the FilePath of the Latest Downloaded File :sweat_smile: ?


Invoke code: No compiled code to run
error BC36646: Data type(s) of the type parameter(s) in extension method ‘Public Function OrderByDescending(Of TKey)(keySelector As System.Func(Of String, TKey)) As System.Linq.IOrderedEnumerable(Of String)’ defined in ‘System.Linq.Enumerable’ cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error. At line 1
error BC30456: ‘CreatedDate’ is not a member of ‘System.IO.FileInfo’. At line 1


@Ana_Shrivastav Are you using Invoke Code Activity or did you use it in an Assign Statement? :sweat_smile:

You can use Assign activity to get file(s) from Downloads folder
Left side is array variable
Right side is Directory.GetFiles(“Download Folder Path”, “*ABC_IU-Investors.xls”, SearchOption.TopDirectoryOnly)

Then get first element of above array or use For Each activity to loop and process file by file.


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