How to move donwloaded reports with same name to a destination folder of our choice

I have a quick question. Suppose there is a file that is downloaded. For ex:- the name of file on first download is Ravi.pdf and the name on the second report is Ravi (2).pdf. I need to move the latest file to some other destination folder and rename it to Ravi.pdf. In case there is already pre existing file with Ravi.pdf in the destination folder it should get overwritten with new one and the name should remain same.

I mean i need to grab the latest report which i downloaded and move to a destination folder with the same old file name. I have seen that move file activity works for overwriting but how do I grab the file from the latest download and move? Suppose Ravi(3).pdf is the latest one I need to move it to Ravi.pdf in destination folder and overwrite the previously downloaded file. Suppose if download report once again it will be ravi(4).pdf So major concern is how to grab the files which keep changing like that and overwrite in the destination folder with same name.

See if this helps:

strFileToMove= Directory.GetFiles(folder_path,"Ravi*.pdf").OrderByDescending(Function(d) New FileInfo(d).CreationTime).First

1 Like

Yes, thank you. It worked.

1 Like

Sort_Dir_files_last_modified.xaml (6.1 KB)

@vvaidya I have a doubt here, In the folder path in the xaml the directory I am working is with my local machine if I want to run on your machine how should I get your downloads directory and how should I move file from your downloads directory to the place where your Uipath project is working on. Can you help me with that?

See if this works?


1 Like