Question

how to get the correct downloaded file

  • 30 December 2022
  • 11 replies
  • 360 views

Badge +2

Hi,

I have created a bot where it runs and downloads the file but I'm confused about how to get the correct downloaded file in the bot. (The one that I download using a bot, I need to open the downloaded file using the same bot ).


11 replies

Userlevel 7
Badge +13

Hi @Anil 8113 ,

 

I hope you would have assigned a name to that file. You can specify the file name with its correct path directly while attempting to open it or can assign the full path to a variable and use that variable later.

 

If this downloading is one-time process per bot execution, I would suggest using the IF → File Exists condition to check the same file is present inside the downloads folder. Then you can use the File → Delete if the file present before downloading the same file during the next bot run.

Badge +2

Hi Padmakumar,

Thank you for your prompt response!

The file name changes every time when I hit download. ( To be precise, numbers get added to the filename.  how can I make the bot to pick the recent one? 

 

Example file names:

Plan_04

Plan_10

Plan_53

Lets say the recent one is Plan_04, how do I pick that one from downloads folder?

Badge +2

@Anil 8113 

 

use for each file in folder and you can order by the last modified or last created time and the first one you get would be the latest file

Hope this helps

cheers

Userlevel 7
Badge +13

Hi Padmakumar,

Thank you for your prompt response!

The file name changes every time when I hit download. ( To be precise, numbers get added to the filename.  how can I make the bot to pick the recent one? 

 

Example file names:

Plan_04

Plan_10

Plan_53

Lets say the recent one is Plan_04, how do I pick that one from downloads folder?

Is this number system generated or are you assigning with the file name?

 

Badge +2

Hi Padmakumar,

that is system generated one, I'm not assigning any name. 

Userlevel 7
Badge +13

Hi Padmakumar,

that is system generated one, I'm not assigning any name. 

 

Ok. 

If it is system generated, you can rename the file right after downloading it through File → Rename action and assign this name to a Variable. Later on, use that variable to open this file. I would suggest using the IF → File Exists condition to check the same file is present inside the downloads folder. Then you can use the File → Delete or use the File → Move action to move that file to a different location (If you need to keep it) if the file present before downloading the same file during the next bot run.

 

I hope you get the logic.

Badge +2

okay, sorry to ask too many questions. I am new to this, so I want to make sure I do it right. 

how can I use that rename action in the same bot when I don’t know what the file name will be? 

If I understand correctly, for rename action - I need to select the existing file in downloads folder and put the newname, correct? 

my current bot steps

  1. access website
  2. select data
  3. click download 
  4. system generated file name downloaded in (downloads folder)
  5. need to open system generated file (the file from step 4) 

Can you give me the link so that I could watch and do it? I am using automation anywhere version 11. 

Userlevel 7
Badge +13

okay, sorry to ask too many questions. I am new to this, so I want to make sure I do it right. 

how can I use that rename action in the same bot when I don’t know what the file name will be? 

If I understand correctly, for rename action - I need to select the existing file in downloads folder and put the newname, correct? 

my current bot steps

  1. access website
  2. select data
  3. click download 
  4. system generated file name downloaded in (downloads folder)
  5. need to open system generated file (the file from step 4) 

Can you give me the link so that I could watch and do it? I am using automation anywhere version 11. 

 

Yes, you are right. You can use Loop - File in Folder action to loop through the downloads folder and use the Break action as well. So, soon after bot picked up the first file (which will be the recent downloaded file), it will exit the loop and go for renaming it.

Else, I can provide you a better approach. Instead of downloading the file, the browser will ask you to save file under which location each time. So that, you can choose the location plus assign a suitable name to that file as well. Sounds good right?

You have to enable the below option in browser through which the bot is downloading the file.

 

So, each time, a Save As window will pop-up and you can mention the file name and decide the location as well.

Userlevel 5
Badge +14

@Anil 8113 :

  • I suggest to create a new folder (botdownload)
  • Change setting in browser by default down load to this new folder
  • Once file downloaded move file to required path/folder and rename
  • In this process you will get only latest downloaded file in botdownload folder and you can manage the file with rename or anything you wanted to… once action completed, you can archive or delete if not required.
Userlevel 5
Badge +9

@Anil 8113 ,

You can use an approach with IF-Condition relative to run time.

 

 

In a Loop action for Each file in folder, read the files  and get name and extension in a dictionary. Then with an IF FIle data action set a condition relative to runtime by a estimated time of the downloads.

 

HTH

Regards.

Badge +4

I would save file to specified location that isnt the downloads folder. At each run clear folder or create folder (overwrite) and then loop that folder once file is saved. This would be the most reliable way to ensure you arent picking up incorrect files. While techniques mentioned above may work, it isn’t reliable.

Reply