cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Radhika1
Helper IV
Helper IV

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 @shindomo
  • 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

shindomo
Continued Contributor
Continued Contributor

Hello @Radhika1 

 

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
shindomo
Continued Contributor
Continued Contributor

Hello @Radhika1 

 

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.

Thank you @shindomo 

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 @shindomo
  • 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

shindomo
Continued Contributor
Continued Contributor

Hello @Radhika1 

 

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

Thanks @MichaelAnnis 

Thanks @shindomo 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (1,833)