Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Triggers
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Resources
  • Get help with flow
Menu

How to write a condition ‘if file was found’ in Power Automate

Posted on November 29, 2020January 27, 2022 by Tom

“I am using Power Automate action ‘Get Files (properties only)’ with a Filter Query to find the file, but how can I write a condition to test if a file actually was found?”


The ‘Get files (properties only)’ action returns an array. If a file (or more files) was found, the array will contain the file, otherwise it’ll be empty. With that, you’ve got two options, depending on what you want to achieve. Do you need to do some action when there’s a file, or when there’s no file?

Action only when ‘file was found’

To process file(s) found by the ‘Get items’ action you don’t necessarily need a ‘Condition’. You can use the existing action ‘Apply to each’ that kind of includes the evaluation ‘if array is empty’. If you input an empty array into ‘Apply to each’, it has nothing to process. Each = nothing, the whole loop, including all actions inside, will be skipped.

Power Automate action when file was found

Action when ‘file was not found’

The other option is to use ‘Condition’ action. As already mentioned, the file(s) returned by ‘Get files’ action are in an array. If there’s isn’t any file, the array is empty. I already wrote a post on using empty values in conditions, so in short, empty array = []. But you can’t use that directly in the ‘Condition’.

Power Automate empty array condition error

You must bypass the validation by using one of the options below.

Empty array variable

Empty array variable, created just for this condition. Compare the ‘value’ output of ‘Get files’ with the empty variable and that’s it. Decide what should happen if there’s no file ([value] is equal to [empty array]) and when there is a file ([value] is not equal to [empty array]).

Power Automate empty array condition

Length() expression

Another option is to use the length([value]) expression in the condition. When using length() on an array with files, it’ll return how many files the array contains. If it’s greater than 0, there’s at least 1 file. If it’s not greater than 0, the array is empty = there’s no file.

Summary

Both of the options above achieve similar goal, with a small difference though. The first option, using ‘Apply to each’ is better for situations when you need to process the file(s) (if they exist). It can be preparation to attach them to an email notification, or to a task.

The second option, using a direct ‘Condition’ is a simple check if there’s a file or not. It doesn’t matter if it’s one or more, you just need to confirm that some file exists. No further processing necessary if it does.

Just make sure that your Filter Query is correct and returns the file(s) if there’s at least one.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


NEW! Master the HTTP requests to SharePoint with a new cheat sheet!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Hello and welcome!

My name is Tom and I'm a business process automation consultant and Microsoft MVP living in the Czech Republic. I’ve been working with Microsoft technologies for almost 10 years, currently using mainly Power Automate, SharePoint, Teams, and the other M365 tools.

I believe that everyone can automate part of their work with the Power Automate platform. You can achieve a lot by "clicking" the flows in the designer, but you can achieve much more if you add a bit of coding knowledge. And that's what this blog is about.

To make the step from no-code Power Automate flows to low-code flows: using basic coding knowledge to build more complex yet more efficient flows to automate more of your daily tasks.

  • Use Power Automate to forward Outlook events upon registrationJanuary 29, 2023
  • Why the condition is false for the same numbers (Power Automate)January 25, 2023
  • How to forward event invitation to other calendar (Power Automate)January 22, 2023
  • Run ‘For selected item’ flow from non-default environment (Power Automate)January 18, 2023
  • Hide button in SharePoint list after Power Automate flow startedJanuary 15, 2023

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes