Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Unanswered

Duplicate FIles in a sharepoint

Like (0) ShareShare
ReportReport
Posted on 3 Dec 2020 18:56:52 by 10

I have a flow that I am using to upload a file (an image) to a sharepoint folder. The issue I want to avoid is having duplicate file names replacing the old ones. Is there a way to check the filename against the directory and if the name already exists to aphend a _1 _2. (ex. xxx_1.jpg xxx_2.jpg) like windows would? If not is there some other unique identifier I could append to the file name besides a timestamp to prevent the file overwrites?

  • jstryk Profile Picture
    10 on 04 Dec 2020 at 19:56:19
    Re: Duplicate FIles in a sharepoint

    So I attempted to use the Move File sharepoint action in the flow but it errors out because the source and destination folder are the same. For some more clarification the file (image) is named in the app itself and duplicates are going to be very common because it is going to be named with a non unique identifier. My thought after seeing the file move action was to just compare the "JPG name"(name of the file) field I have in the power app against the directory and then use respond to power apps to just notify the user before any file creation takes place.

  • tom_riha Profile Picture
    10,085 Most Valuable Professional on 03 Dec 2020 at 20:00:16
    Re: Duplicate FIles in a sharepoint

    Hello @jstryk ,

    I can imagine a solution using 'Get files' on the library with 'Filter Query' to check if there're already files with that name. The 'Filter Query' below will check if there're files that already contain the filename and return all of them.

    substringof('[FileName without extension]', FileLeafRef)
    
    Note:
    [..] is a placeholder, it must be filename WITHOUT extension

     e.g. if your file is xxx, it'll return xxx.jpg, xxx_1.jpg, xxx_2.jpg.... all files that have the filename in title will be stored in the 'value' dynamic content. Then you use expression length('value') to calculate how many items were found, and you add that number at the end of the new file (1st file doesn't have any number, 2nd has _1, 3rd _2...).

    There're limitations though. If the file names are similar, e.g. files xxx.jpg and xxxyyy.jpg, it'll return both when searching for xxx in file name (and you'll get files xxx.jpg, xxxyyyy.jpg, xxx_2.jpg). And also if there're multiple files with the same name uploaded at the same time they could both use the same number.

    In the end I think using a timestamp is much easier and probably more reliable option.

     

  • abm abm Profile Picture
    32,464 Most Valuable Professional on 03 Dec 2020 at 19:16:40
    Re: Duplicate FIles in a sharepoint

    Hi @jstryk 

     

    You could use Move file action step or Filter Query. Please have a look at my videos.

     

    https://www.youtube.com/watch?v=B9ZxAd9JVVo

     

    Also you can filter using the filter query

     

    https://www.youtube.com/watch?v=bSkWdDnhCmQ&t=1s

     

    Thanks

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Building Flows

#1
stampcoin Profile Picture

stampcoin 61

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 47 Super User 2025 Season 1

#3
rzaneti Profile Picture

rzaneti 29 Super User 2025 Season 1

Overall leaderboard
Loading started