cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

How to check the version of the same filenames

Hi,

 

I have two files with the same file name but different version. I need to check the latest version and copy them to the folder. 

Any ideas on how to implement ?

 

File names : 10mL ABC 19875-05.pdf

                    10mL ABC 19875-06.pdf

 

Currently, I am getting the files in a folder which has 10mL ABC 19875*.pdf, so I am getting all the files which matches. I need to copy the file which has 06.pdf. Please help.

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions

Assuming all files are formatted the same way, ex. ##ml XXX #####-##.pdf, then you could do the following:

 

  • After you have sorted as previously indicated by @Anonymous, 
  • For Each %CurrentItem% in %Files% 'CurrentItem in this case would be each row ex. %Files[0]%
    • Get Subtext of %CurrentItem.Name%, Start of Text, character position = 0, Length is Number of Characters = 15; set the subtext to %NewSubText%
    • If %CurrentItem% = %Files[0]%
      • Set variable %LastSubText% to %NewSubText% 'on the next loop, we will match these up
      • Next 'this will ignore the first file and move to the next file
    • EndIF
    • If %NewSubText% = %LastSubText%
      • Delete %CurrentItem%
    • EndIF
  • End 'For Each

 

This will loop through each filename ignoring the first time the 15-character string pops up.  Each line will look for a match from the previous 15 characters, and if they are a match, it will delete the file, if not, it will move on.

 

Best of Luck!

 

 

View solution in original post

Anonymous
Not applicable

Hello @Anonymous 

 

Just remove the item %Files[0]% from the list.

 

shindomo_1-1633619587278.png

 

After that, you have the list of files except the latest one. That's the list of files you want to delete.

 

shindomo_2-1633619676077.png

 

Now you can delete files except the latest one using variable %Files%. It's so simple, but it works well as you imagined. 🙂

 

shindomo_0-1633619559487.png

 

Thank you.

 

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hello @Anonymous 

 

We have "Sort by" dropdown menu in Advanced options in action "Get files in folder". You should make it sort by "Name" and let it "Descending" order in this scenario.

 

shindomo_0-1633602836756.png

 

Using configuration above, the latest version of your files will always be at the beginning of the %Files% list.

 

shindomo_1-1633603285772.png

 

Then you can copy the latest version of file referring by %Files[0]%

 

shindomo_2-1633603305788.png

 

Thank you.

Anonymous
Not applicable

Thank you @Anonymous 

It is so helpful! one more thing, for suppose I have many files having same file names and different version and I have to keep the latest, rest of the files have to be deleted because I am working on the same folder so instead of copying, I prefer to delete the unwanted files. 

Assuming all files are formatted the same way, ex. ##ml XXX #####-##.pdf, then you could do the following:

 

  • After you have sorted as previously indicated by @Anonymous, 
  • For Each %CurrentItem% in %Files% 'CurrentItem in this case would be each row ex. %Files[0]%
    • Get Subtext of %CurrentItem.Name%, Start of Text, character position = 0, Length is Number of Characters = 15; set the subtext to %NewSubText%
    • If %CurrentItem% = %Files[0]%
      • Set variable %LastSubText% to %NewSubText% 'on the next loop, we will match these up
      • Next 'this will ignore the first file and move to the next file
    • EndIF
    • If %NewSubText% = %LastSubText%
      • Delete %CurrentItem%
    • EndIF
  • End 'For Each

 

This will loop through each filename ignoring the first time the 15-character string pops up.  Each line will look for a match from the previous 15 characters, and if they are a match, it will delete the file, if not, it will move on.

 

Best of Luck!

 

 

Anonymous
Not applicable

Hello @Anonymous 

 

Just remove the item %Files[0]% from the list.

 

shindomo_1-1633619587278.png

 

After that, you have the list of files except the latest one. That's the list of files you want to delete.

 

shindomo_2-1633619676077.png

 

Now you can delete files except the latest one using variable %Files%. It's so simple, but it works well as you imagined. 🙂

 

shindomo_0-1633619559487.png

 

Thank you.

 

Anonymous
Not applicable

Thanks @MichaelAnnis 

Anonymous
Not applicable

Thanks @Anonymous 

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

PWREduCon768x460.png

Join us at PWR EduCon - A Power Platform Conference

Learn from the top Power BI, Power Apps, Power Automate & Power Virtual Agents experts!

Power automate tips 768x460 v2.png

Restore a Deleted Flow

Did you know that you could restore a deleted flow? Check out this helpful article.

Users online (3,222)