web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / adding a condition tha...
Power Automate
Unanswered

adding a condition that file must be found before continuing

(0) ShareShare
ReportReport
Posted on by 29

I currently have a flow that happens every day at 0400.

 

This is a rough idea of the flow

shinegull_3-1668645570898.png

shinegull_0-1668645467657.png

shinegull_1-1668645485290.png

 4 of these get file content, for 4 different files

shinegull_2-1668645531449.png

Then send as an email with all four files

 

 

However, the recurring portion is kind of a make do and hope for the best. so it set to start late enough that the files that this flow gathers together should be made by that point anyways. 

However, I'm trying to cut out the human error/ human variable portion as much as possible.

 

I'd like to change/add 2 parts to this

First portion is a condition. Basically, I want the flow to start way earlier. but I need the flow to wait until all four files are ready before sending. But I have no idea how to do that. 

I know exactly where the files will be, and I know the exact name of the file as well. Location and file name format will not change.

How do i set up a condition where the flow will be on standby until all 4 files at the specific folder location and file name is ready before continuing?

 

Id also like to set something up that if by x time of day, if the flow has not finished, it should stop the flow until the next time slot comes around. (This part not as important as the files should be made roughly every 24 hours anyways)

Categories:
I have the same question (0)
  • CFernandes Profile Picture
    8,402 Most Valuable Professional on at

    @shinegull You can use the length parameter to count the files..

     

    The formula will be - 

     

    length(outputs('Get_files_(properties_only)')?['body/value'])

     

    CFernandes_0-1668661214487.png

     

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

     

    P.S. take a look at my blog here and like & subscribe to my YouTube Channel thanks.

  • shinegull Profile Picture
    29 on at

    Not sure if my input is right. it speeds through the flow really fast. doesnt even wait for all 4 files to be in folder. I think its counting the other files in the folder as well.

    I won't know exactly how many files will be in the folder at the time.  Is there no way to identify a file exists before continuing? a file with the exact name. Since i will always know what expected file name will be.

     

  • grantjenkins Profile Picture
    11,063 Moderator on at

    A few questions:

    1. Will the filenames for the 4 files always be the same (never change)?
    2. Will the 4 files all live in the same folder as each other?
    3. What happens to the files after you send them at attachments via email?
      1. Will they be removed ready for the next day?
      2. If not removed, how will you know that there are new files?

     

  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    Assuming all the files are located in the same folder and excluding any logic about cleaning up the files after they've been emailed - this is how I would achieve what you're after.

     

    Note that this will also work regardless of how many files are in the same folder as it will look for 4 specific file names including the extension.

     

    Below is the full flow. I'll go into each of the actions.

    grantjenkins_0-1668778402342.png

     

    Within the Do until loop:

    grantjenkins_1-1668778437512.png

     

    And within the Yes and No branches:

    grantjenkins_2-1668778493819.png

     

    Recurrence would be set to when you want to start each day which you said was 4AM.

    grantjenkins_3-1668778547130.png

     

    Initialize variable File Count (fileCount) will track how many files were found. We will keep looping until we find all 4 of them.

    grantjenkins_4-1668778628651.png

     

    Initialize variable Attachments (attachments) will contain all the attachments once all 4 files are found.

    grantjenkins_5-1668778707711.png

     

    Do until will keep going until fileCount is equal to 4 (we've found our 4 files). However, we have also set the limits so that it will stop if it runs 24 times or for 6 hours (PT6H). This will handle your last requirement where you want to cancel after a certain period of time. Note that I've set it for 24 times because we have a Delay within the loop of 15 minutes (will try to find the files every 15 minutes, or 4 times an hour) which equates to 24 times over 6 hours (same as the 6 hour limit we specified).

    grantjenkins_6-1668778847796.png

     

    Get files (properties only) will retrieve all files within a specific folder where the filename (including extension) is equal to one of my 4 file names I'm looking for. We use FileLeafRef for this in our Filter Query. In my example I'm looking for 4 documents called Test 01.docx, Test 02.docx, Test 03.docx, and Test 04.docx.

    FileLeafRef eq 'Test 01.docx' or FileLeafRef eq 'Test 02.docx' or FileLeafRef eq 'Test 03.docx' or FileLeafRef eq 'Test 04.docx'

     

    grantjenkins_7-1668779150433.png

     

    It will then set the fileCount variable to the length of items returned. We use the following expression for this:

    length(outputs('Get_files_(properties_only)')?['body/value'])

     

    Condition checks if fileCount is equal to 4 (found all our files).

    grantjenkins_8-1668779300973.png

     

    If the result is No (not 4 files found) then we set a Delay of 15 minutes. After the delay it will go back to the start of the Do until and run through again.

    grantjenkins_9-1668779368059.png

     

    If the result is Yes (we have found our 4 files) then we do the following:

     

    Apply to each will loop over each of our 4 files.

    grantjenkins_10-1668779459211.png

     

    Get file content will get the file content using the Identifier field.

    grantjenkins_11-1668779518964.png

     

    We then append to the attachments array an object with the Name and Content.

    grantjenkins_12-1668779599081.png

    The expression for the object is:

    {
    "Name": @{items('Apply_to_each_file')?['{FilenameWithExtension}']},
    "ContentBytes": @{body('Get_file_content')}
    }

     

    Lastly, after the Apply to each, we use Send an email to send the email with the 4 attachments. To add the attachments, we click on Show advanced settings, then for the Attachments, click on the button on the right, then select the attachments array.

    grantjenkins_13-1668779767768.png

     

    The email should look something like:

    grantjenkins_14-1668779827269.png

     

    And below is the Document Library Folder that contains 5 files, but it only picked up the ones that I specified in my Filter Query.

    grantjenkins_15-1668779875690.png

     

    Again, I'm not sure what you then do with your files in the folder. Do you clear them out ready for the next day?

  • shinegull Profile Picture
    29 on at

    Thank you very much! There is a lot of information in your reply, which is incredibly helpful! running some final tests on the flow now, mostly cosmetic changes. but initial runs look like there are no issues so far and works very well!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 523 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 406 Moderator

#3
abm abm Profile Picture

abm abm 245 Most Valuable Professional

Last 30 days Overall leaderboard