Sometimes it is useful to create small helper flows to get a small tasks done. Today I needed to check if a file exists or not and all I had was the URL of the site and the file path.
The general flow setup
Table of Contents
In my Child flow I’m going to use the Get file metadata using path action inside the well known Try-Catch pattern. So that when my file is not found the catch scope will make sure that I return a false value while if the file is found a true value is returned.

I just need to make sure that the Respond action is returning true or false.

Yes, you could also implement this without the scope actions. But If I wanted the extend this flow in any kind of way at a later stage then the scope actions do make it easier to understand the flow. Hence, I always add these scopes.
The Trigger input parameter
I’ve added two parameters to my trigger. First of all I will need the URL to my site. And the I need the Path to my file. I want to make sure that the file path can be supplied in various different ways, but I will handle that in the configuration of the following steps.

Check if a file exists or not
To check if a file exists we only need to supply the Site URL from the trigger input parameters and we need to supply the File Path. Now you might find that the File path will come in all sorts of variations.

Some things that I have come across is:
- spaces in paths have been replaced with ‘%20’
- no leading ‘/’ in the path
Our SharePoint action however wants spaces and a leading slash. The following expression will handle all of this. So if there is no leading slash then we will add it and the spaces will be put in place.
replace( if( equals( first(triggerBody()?['text_1']), '/') , triggerBody()?['text_1'] , concat('/',triggerBody()?['text_1']) ) ,'%20', ' ')
Now all we have to do is call this flow from flows that needs to check the existence of the file. With a few small steps we have a nice little reusable flow to check if our file exists or not.
Discover more from SharePains
Subscribe to get the latest posts sent to your email.