How to download randomly downloaded file(file is downloaded from a website, want to rename most recentlyrandomly downloaded file

how to download randomly downloaded file(file is downloaded from a website, want to rename most recently randomly downloaded file

@munazza_khan

Welcome to our UiPath community.

Try below expression.

LatestFile =  System.IO.Directory.GetFiles("FolderPath").Select(Function(f) New FileInfo(f)).OrderByDescending(Function(b) b.LastWriteTime).ToList(0).ToString

Above expression will give you last downloaded file and then you can use Move File activity to rename the file.

1 Like

got it. but i dont know how to move recent file with a new name.

@munazza_khan

As I mentioned in the previous post, you can use Move File activity and pass source and destination paths.

Source Path - LatestFile (You will get it from above expression)

Destination Path - “Destination Path”+“New Filename”

1 Like

i m passing “from path” as an variable in move activity but getting error :slightly_frowning_face:

@munazza_khan

Can you print the from path using Message Box activity before Move File activity and check whether it’s printing correct file path or not. And also May I know what error are you getting here ?

Hiii @munazza_khan

latest file will give only file name in that folder , you need to use folder path along with that file name to get complete path
in from field of activity.

for eg if you are using C:\users\Test\Uipath\downloadfolder
you need to pass the above folder path to that file name so that it will work please check on this