cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Check if string exists in any filenames of SharePoint Library

Hello,
 
I would like to take a string variable output and compare it against a list of file names from a SharePoint library to see if any of the filenames contain this string.
 
I am trying to create a condition that will check if an array of the filenames contains the variable with the string I want to compare.  
 
ex.  string variable = 005, 011 compared against possible filename 20201026_(005, 011) site.xlsx would = True
ex.  string variable = 004, 012 compared against possible filename 20201026_(005, 011) site.xlsx would = False
 
I have tried a few things but I am not having success. 
 
 

2020-10-26 14_10_43-Window.png

2020-10-26 14_12_15-Window.png

2020-10-26 14_11_54-Window.png

 
 
Any help would be greatly appreciated. 
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Yes, you can replace <yourString> with variable,  but don't forget the apostrophes around it.

 

With the condition, you have 2 choices:

1. If you don't need any action when there's no file, you can use just 'Apply to each' on the output of that action. It'll run only if some files were found, otherwise it'll be skipped (as 'to each' = 'to nothing').

2. If you need also some action when there's no file, you'll need a condition that will check if the 'value' output of that action is not an empty array (the 'value' output of 'Get files' is an array, either it has all the file information or it's empty = [] ). As condition by default can't compare arrays, you'll have to create an empty array variable and use it in the condition.

image.png

 

 

View solution in original post

8 REPLIES 8
Highlighted
Responsive Resident
Responsive Resident

Hi @philalethes when you say "20201026_(005, 011) site.xlsx" do you mean there could be 7 files ranging from names "20201026_005.xlsx" to "20201026_011.xlsx"?

Highlighted

@Amanthaper Thanks for clarifying.  I probably could have made that more clear.

 

The (005, 011) is an ID for a specific piece of equipment, it is not a range. 

 

I am trying to take the id I already have saved in my string variable (my example was 005, 011) and check to see if any files contain that id.  I hope that helps clear it up.

 

Thanks!

Highlighted

@philalethesI would extract 005, 011 from the Excel filename and remove the space from both values and compare them.

Below flow worked using your exact examples:

PAUG_Excelfilename1.png

PAUG_Excelfilename2.png

 

(1) Remove space from 005, 011:

replace(variables('Filename'),' ','')
(2) Format Excel file name to get 005,011 using "Name" output:
Replace(Replace(Replace(Substring(items('Apply_to_each')?['{Name}'],add(lastIndexOf(items('Apply_to_each')?['{Name}'],'_'),1),sub(Length(items('Apply_to_each')?['{Name}']),add(lastIndexOf(items('Apply_to_each')?['{Name}'],'_'),1))),' ',''),'(',''),')','')
 
To use this formula with "File name with extension" use another Replace function to swap excel extension with a blank value.
 
Hope this helps,
Aman
------------------------------------------------------------------------------------------------------
If my post helps you with your problem or answers your question, please mark it Solved or Answered. This helps anyone with similar challenges. If you like my response, please give it a Thumbs Up.
------------------------------------------------------------------------------------------------------

 

Highlighted

@Amanthaper Thanks for the idea of comparing the strings without the comma!

 

The part I seem most hung up on right now, is I am trying to compare my "key" (005, 011) against all the files in a SharePoint library to see if any of the files contain that key.

 

I have so far tried writing the list of file names to an array, but I can't figure out how to compare my key, which is a string, against the items in the array.  I keep getting errors about my results type being objects or strings instead of an array when I try a few different methods of making that comparison. 

 

Any thoughts on that piece?

 

Thanks!

2020-10-26 14_10_43-Window.png

Highlighted
Solution Sage
Solution Sage

If you're trying to filter files from a library that contain a specific string in the file name, you can do that directly in the 'Get files' action using the OData Filter query, just put there filter in format:

substringof('<yourString>', FileLeafRef)

Replace <yourString> with the string you want to find in the file name and the action will return only the relevant files. 

image.png

Highlighted

@tom_riha Interesting!  Will I be able to use a variable in that query?  The string "key" I am checking with is dynamically generated from a new file being created that is then stored in a variable.

 

Also, I will be using this in a branching Apply to Each logic, so if it finds a match it goes down the yes branch and if it doesn't find a match it goes down the no branch.  Is there a way to use this filter method in conditional branching logic?

 

Thanks!

Highlighted

Yes, you can replace <yourString> with variable,  but don't forget the apostrophes around it.

 

With the condition, you have 2 choices:

1. If you don't need any action when there's no file, you can use just 'Apply to each' on the output of that action. It'll run only if some files were found, otherwise it'll be skipped (as 'to each' = 'to nothing').

2. If you need also some action when there's no file, you'll need a condition that will check if the 'value' output of that action is not an empty array (the 'value' output of 'Get files' is an array, either it has all the file information or it's empty = [] ). As condition by default can't compare arrays, you'll have to create an empty array variable and use it in the condition.

image.png

 

 

View solution in original post

Highlighted

@tom_riha Brilliant!  Comparing the array to an empty array did the trick!  Thank you for your help!

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Top Solution Authors
Top Kudoed Authors
Users online (10,993)