How to rename a downloaded file. File downloaded has no specific name

uiautomation
uipath

#1

Hello all,

In my sequence I download excel file from website. Name of excel file is not static. It keeps on changing.
I want to rename this file.
Example:-
downloaded file can have name like:

“assetRegister_23/12/1988_092A.xls”
“assetRegister_24/12/1988_B92A.xls”
“assetRegister_25/12/1988_0C2A.xls”
“assetRegister_26/12/1988_SC45.xls”

I want to change file name to “BOT_input.xls”


#3

Why my post is withdrawn


#4

If you want the file to be renamed and to be in the same folder you can use Move function, if different folder you can use copy file activity with different filename.

Note: There is Move File Activity as well, you don’t have to use Invoke Method


#5

Yes but the catch here is I cannot specify the name of file that need to be renamed. coz at every download name of file changes.


#6

How many files will you be having the the download folder at a given time?

If one, then just pick that and get the filename using Directory.GetFiles(@“YOUR PATH”)

If multiple, you can get most recent file DirectoryInfo(@“YOUR PATH”).GetFiles().OrderByDescending(Function(x) x.LastWriteTime)


#7

Yeah one file at a time…


#8

Then use this Path.GetFileName(“your path”)


#9

Hi I am using “DirectoryInfo(@“YOUR PATH”).GetFiles().OrderByDescending(Function(x) x.LastWriteTime)” coz I may have multiple files in future but this gives error.


#10

Thankyou so much @vvaidya … really appreciate your help. KUDOS


#11

Hi vvaidya,

in the below function, what is Function(x) x.?

DirectoryInfo(@“YOUR PATH”).GetFiles().OrderByDescending(Function(x) x.LastWriteTime)

Could you please explain as I am getting the error while executing.