Move file, get the last file in a folder

Hello,
I download several files in the “Download” folder I would like to move a specific file that I download from an automation.
The problem is that Mozzila downloads automatically and the file changes its name in the following sequence.
For example:
File
File(1)
File(2)

And so on … how do I always get the last file and move it to the folder I want?
Folder I want: “C:\Users\MyUser\Documents\Uipath\ Project1\ Files”

First off, you need to go into your Mozilla settings and change the default download folder options. For automation, you want to “know” where you are downloading stuff. By doing this, you can also choose the filename, therefore, you don’t need to do anything special and just use the filename which you used to download the file to.

However, just to share a method to accomplishing what you originally ask, you can grab the last file with some .net.

Directory.GetFiles(downloadDir, filename+"*.pdf").OrderByDescending(Function(f) new FileInfo(f).CreationTime )(0)

so it pulls in all files that have a certain pattern (I used .pdf as extension and filename is a variable to represent what the file will be called). Then, orders by the creation time… and hopefully I did that right :thinking:

Like I said though, I don’t recommend dealing with this, and just set your default download location in Mozilla (and Chrome if you use that browser)
EDIT: you want to set it to “ask where to download”

1 Like

@ClaytonM I understand your suggestion. But I want the downloads of this automation to be in the folder of this project. That way, if I have more projects I will need to put it in another folder. I even tried to automate to delete the current path that appears as a suggestion to save the file and type in the location I want, but there is a lot of error and I want something that is as dynamic as possible.

@guilas I think in your screenshot, that is the Save As dialogue when you try to download the file, correct? Just place the full path in the filename textbox. You don’t need to put the folder in the address bar like it appears you were trying to attempt.

Let me know if you need other assistance. Regards.

Dear @Guilas

The best approach to solve this issue is enabling always ask where to save in firefox options. you can always save in which ever directory you want.

Please mark as solution if you found this useful :slight_smile:
Regards
Roshan

1 Like

@ClaytonM I didn’t know, thank you very much!
Solved here

1 Like

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