web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Check for duplicate fi...
Power Automate
Suggested Answer

Check for duplicate file names in SharePoint

(0) ShareShare
ReportReport
Posted on by 62
I'm having trouble with checking for duplicate file names. I'm getting files from email and then creating files in a folder on SharePoint, and I want to check if the file name already exists in SharePoint so that it automatically increments the number at the end, like abc(1).pdf, abc(2).pdf, that way it won't overwrite an existing file. Please help me, thank you everyone.
 
 
I have the same question (0)
  • David_MA Profile Picture
    14,956 Super User 2026 Season 1 on at
    You can use a get files action with a filter query to search for files with the name: FileLeafRef eq 'TestFile.docx'
     
    FileLeafRef is the internal field that stores filenames. You can then use a length() expression to see if the value is greater than 0. If it is, the document library contains a file with that name.
     
    Of course, before you can name the new file 'TestFile1.docx', you will need to check if that filename already exists. If it does, you will need to keep doing this until it finds a name that hasn't been incremented. 
  • Suggested answer
    trannguyen0410 Profile Picture
    62 on at
     
    I was using 'do until' to check whether the file exists, but the loop kept running forever. Now I switched to checking with 'get file metadata using path', and the condition is 'empty(body(Get_file_metadata_using_path)) = true', then set the variable to be the filename from the email; if false, set the variable to a new filename in the format yyyyMMddHHmmssfff. Would that be okay?
  • David_MA Profile Picture
    14,956 Super User 2026 Season 1 on at

     you can, of course, set up the workflow any way that works for you. However, you will need to show your workflow and what you had in mind. I am not understanding what you propose to do through a do until action.
     
    I would suggest checking if the file already exists as I posted earlier:
     
     
    However, if you're going to name the files with this format, yyyyMMddHHmmssfff, I would just always name the files with that format. The odds of generating two files with that naming convention will be astronomically low if not impossible.
     
  • trannguyen0410 Profile Picture
    62 on at
    I always use yyyyMMddHHmmssfff to create filenames.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 377

#2
11manish Profile Picture

11manish 279

#3
David_MA Profile Picture

David_MA 234 Super User 2026 Season 1

Last 30 days Overall leaderboard