Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Outlook
    • Planner
    • Power Apps
    • SharePoint
    • Teams
  • Triggers
  • Ready to use solutions
    • Approval Process Template
    • Task Delegation App
    • The Ultimate Power Automate expressions cheat sheet
    • Power Automate HTTP requests to SharePoint cheat sheet
    • Power Automate HTTP requests to Graph API cheat sheet
  • ABOUT ME
  • Get help with your flow
  • POWER PLATFORM SERVICES
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.


πŸš€ Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

Leave a Reply Cancel reply

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

πŸš€ Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

Still exchanging emails to get things approved?

Use the Approval Process Template and the Task Delegation App to skip the hard part and deploy an automated, fully functional approval solution on a SharePoint list in minutes! And then the next one, and the next one...

Approval Template Preview ✨ Learn more ✨

Turn ideas into flows with ease!

Grab the complete Power Automate Cheat Sheet Bundleβ€”everything you need to master expressions, SharePoint HTTP calls, and Graph API in Power Automate.

Cheat Sheet Bundle Preview ✨ Get the Cheat Sheets

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with thousands of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2025 Let's POWER Automate | Theme by SuperbThemes