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?
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.
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.
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
stampcoin
61
Michael E. Gernaey
47
Super User 2025 Season 1
rzaneti
29
Super User 2025 Season 1