cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sabei_sabei
New Member

How to rename downloaded xls-file with changing filename (XXXX_yyyddmm.xlsx)? xxxx = constant; date changes)???

Hi there, 

 

I am facing the following problem: 

 

- I am maintaining a xls-report that needs to be updated with the latest data every month

- for that, I have to download some data (also xls) from a website (which I have automated via Power Automate)

- the download file name consists of two parts, e.g. "download_20220927.xlsx" - part 1 "download_" never changes, part II "20220927" changes always according to the current date when I retrieve the data

- in order that the query in my xls-report works, I need to rename the download to a standardized name, e.g. "Input_data_report.xlsx"

- And there is exactly my challenge: How do I rename a file whose name changes from month to month (or rather depending on the date when I download the file)?

 

Current approach (which doesn't work): 

- I added the action "Click on UI element in window" and saved the current file name 

- that works for this particular download, but the next download (e.g. tomorrow or next month) won't work, as the name of the downloaded file changes, hence PA doesn't recognize the file anymore 

- The plain "rename" functions forces me to choose only one particular file (=file name)  

 

Highly appreciate your support here!!! 

Thanks and all the best from Berlin

Philipp 

3 ACCEPTED SOLUTIONS

Accepted Solutions
sabei_sabei
New Member

Unfortunately this approach is also not solving it, as the file name of download is in fact FileName_yyyddmmhhmmss.xlsx (--> so also includes hours, minutes, and seconds) - and that would be impossible to match with a string I guess... 

 

Would it be possible to create a variable that always selects the file in a folder that has been "last modified"? Or maybe to look for a file that contains "FileName*.xlsx" or something like that?  

View solution in original post

You can use Get Files which has an option to sort by the modified or created date and then get just the first item of that list

%Files[0]%

View solution in original post

Pavel_NaNoi
Continued Contributor
Continued Contributor

If I understood this correctly, you can simply:

 

Use a "parse text" action after a get files activity, with the following regex:

"download_\d+" without the quotes,

store the match into a variable and then use that match for the rename file action.

 

If there are multiple new download_###### files where you're downloading then make sure to uncheck "First occurrence only" in the "Parse text" action, and do a for each on the list of matches you get.

 

IF you have outdated download_###### files in the same place as the new download_##### file, then:

use this regex instead: "(?<=download_)\d+" this will get you just the number after "download_" use this number and convert it to date time with the convert to datetime action, from there its just a matter of using if logic, e.g. only select this download file if its date isn't < than today or something similar.

View solution in original post

8 REPLIES 8
PhilipTreacy
Resolver I
Resolver I

Hi @sabei_sabei 

 

Try using Click link on web page and choosing a Right Click 

padrc.png

 

 

You can then click on the Save as link and complete the name of the file as you want it to be saved.

 

Regards

 

Phil

VJR
Super User
Super User

Form a string that will be equal to the file name to be searched.

Output variables after running the below steps.

VJR_3-1664339191057.png

 

Now your MyFileName variable has the name to be looked for as per today's date-

Pass it to the rename action.

 

Make sure the FilePathHere has the \ in the path.

...Of the format C:\Test\download_20220928.xlsx

 

VJR_4-1664339275274.png

 

 

 

 

Thanks @PhilipTreacy! But this doesn't work as I do not have access directly to the file but only over a html button that triggers the download. 

 

sabei_sabei
New Member

Thanks @VJR - Let me try this. I'll keep you posted! 

sabei_sabei
New Member

Unfortunately this approach is also not solving it, as the file name of download is in fact FileName_yyyddmmhhmmss.xlsx (--> so also includes hours, minutes, and seconds) - and that would be impossible to match with a string I guess... 

 

Would it be possible to create a variable that always selects the file in a folder that has been "last modified"? Or maybe to look for a file that contains "FileName*.xlsx" or something like that?  

You can use Get Files which has an option to sort by the modified or created date and then get just the first item of that list

%Files[0]%

Pavel_NaNoi
Continued Contributor
Continued Contributor

If I understood this correctly, you can simply:

 

Use a "parse text" action after a get files activity, with the following regex:

"download_\d+" without the quotes,

store the match into a variable and then use that match for the rename file action.

 

If there are multiple new download_###### files where you're downloading then make sure to uncheck "First occurrence only" in the "Parse text" action, and do a for each on the list of matches you get.

 

IF you have outdated download_###### files in the same place as the new download_##### file, then:

use this regex instead: "(?<=download_)\d+" this will get you just the number after "download_" use this number and convert it to date time with the convert to datetime action, from there its just a matter of using if logic, e.g. only select this download file if its date isn't < than today or something similar.

sabei_sabei
New Member

sabei_sabei_0-1664376805085.png

The download arrives in the format "TimeAndExpenseDetails_yymmddhhmmss.xlsx. which I can select/find through searching for "TimeAndExpense*". Saving this in a variable, I can rename the file (to TimeAndExpensesDetails.xlsx) and move it into the location where the original report pulls the query from the newly replaced file. Problem solved!

 

Thanks all! That did the job! 

 

 

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Top Solution Authors
Top Kudoed Authors
Users online (5,475)