cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Kryptic
Helper II
Helper II

Comparing filename to list of files

Hello,

 

I would like to check if a filename i create in my flow is present in a folder in my FTP server.

 

  • I used 'append to array variable'  to get the name of every file i create
  • I retrieve the list of files by using 'List of files in Output folder',

 

I basically want to check if the created file name (output of the append to array variable) is present in the list of names.

if it is present nothing should happen

if it is not present i want to recieve a email notification

 

Any ideas?

 

Kryptic_0-1600680279962.png

 

 

Kryptic_1-1600680521691.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Thanx for your detailed explanation!

Now, you mentioned that 'different software does something to these files and places the files back into a FTP folder 'Output folder' '.

 

Does this folder modify the original File names? If not, you just nee to apply the strategy I suggested for the Condition action block (operator equals and comparation with the full FileName). I guess you will need to read all files in the folder, then add an 'Apply to each' let's rename it as 'Apply to each filename', then assign as its input the filenames array you already have built; then inside the Apply to each you place the 'Filter array' and the condition.

Now on the left side of the Filter array condition rule you just need to add the following WDL expression...

items('Apply_to_each_filename')

 

Now, if you add 'SEnd an email' on the 'false' branch of the Condition action block, you will receive an email per filename not found.

But you can add an 'initialize variable' at the top of your flow, let's call it 'NotFoundFileNamesArray', type Array, value empty. And... on the 'false' branch of the Condition action block, you can add an Append to array' action block, and add to 'NotFoundFileNamesArray' a new element by means of the following WDL expression...

 

items('Apply_to_each_filename')

 

Now, out of your 'Apply to each' you can include the 'Send an email' action block and add the array to your email body.

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

7 REPLIES 7
efialttes
Super User
Super User

Hi!

So I would add a 'Filter array' action block, assign as its input 'LIST FILES IN OUTPUT FOLDER' value output. THen set its condition rule to evaluate if any filename matches the one you already created. THe approach should be identical to this flow, designed for a totalliy different scenario

Flow_WorksheetExists.png

So in your scenario 'LIST FILES IN OUTPUT FOLDER' should take the role of the 'Get worksheets' action block from my screenshot.

After replacement, you need to adapt 'Filter array' inputs accordingly, and add your notification action block on the 'false' branch of the Condition

 

I am assuming in your folder, two files cannot share the excat same name, so if length is not 1, then it means target file is not defined inside

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Oke i tried following your instruction but i can't get it to work, i'm not very experienced and don't understand the condition.

 

FYI: every filename contains a 'Q'

 

FYI: every time a file gets created it makes a new 'append to array variable' with the filename. So i would have to use a 'apply to each' somewhere i think to check for every file created?

 

Kryptic_0-1600686247166.png

 

Kryptic_1-1600686271186.png

 

Hi again!

 

On the 'Apply to each' question.

The scenario I shared works with one single file. In your case, what I understand from your last screenshot shared is that you need to create more than one file by means of an 'Apply to each', right? And, I assume the input you assigned to 'Apply to each' is an array, right? If not, flow will fail, 'Apply to each' internal logic will not be executed.

 

Now, on the 'Condition' question.

The condition I shared as example was designed for 'exact' worksheet matches, that's why  I selected operator 'equals' and added the target worksheet name on the right.

So, if number of results matching the condition is 1, then we got a match (and we cannot have more than 1 worksheet sharing the same name ina single excel file, right?).

So, if the condition rule you set in your scenario follows the same concept, you will need to choose operator equals and type the target filename (plus extension) on the right. Since you didn't, I believe your requirements need a different approach than the one I shared.

 

And... the condition rule you have just set in your scenario is that filename contains Q. So in theory, this can lead to 0 matches (no files found), 1 match or more than one match, right?

 

But since you are inside an 'Apply to each' that will be executed N times, the first iteration you will have at least 1 file with a Q, the second iteration you will have one more file, and so, and so...

 

So probably it's me, but I don't really understand what's the goal you wanna achieve by using 'contains' operator instead of 'equals' and the full File Name

 

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Thanks for your elaborate reply, i will explain my case with alot of detail below, to make sure there is no confusion to what i want to achieve...

 

Everytime i run this flow i create a random amount files in a 'Apply to each' loop, so this can be file_1.zip ..... file_x.zip (can be any amount of files with any name, but always contains a Q in the name)

Everytime it goes through the 'Apply to each' loop i make an array of the filename.

 

picture of flow step i described above:

Kryptic_0-1600696499894.png

Flow result of the step described above, when creating 2 files (1st file name highlighted at the bottem, if i click next, i get to see the 2nd file name):

Kryptic_1-1600696619278.png

 

I now have my filenames seperated as array...

 

After having created these files in a FTP folder 'Input folder', different software does something to these files and places the files back into a FTP folder 'Output folder' (not important what but just background information).

 

I want to make sure that every file i created in the input folder, is also present in my output folder, that way i can be sure the software did everything correctly. The outputfolder contains a random amount of files, which is always more files than the amount created. My idea was to list the output folder files, and then somehow compare the created files names and check if theyre present.

 

Kryptic_0-1600697709742.png

 

So, in short, I created input folder files:

file_1.zip

....

file_x.zip

 

I listed output folder files:

file_1.zip

.....

file_n.zip

 

What i need to know:

are created files: 

file_1.zip

....

file_x.zip

 

present in output folder

file_1.zip

.....

file_n.zip

 

(n>x ofcourse)

 

If yes -> nothing

if no -> email me with the name of the missing file

 

Thanx for your detailed explanation!

Now, you mentioned that 'different software does something to these files and places the files back into a FTP folder 'Output folder' '.

 

Does this folder modify the original File names? If not, you just nee to apply the strategy I suggested for the Condition action block (operator equals and comparation with the full FileName). I guess you will need to read all files in the folder, then add an 'Apply to each' let's rename it as 'Apply to each filename', then assign as its input the filenames array you already have built; then inside the Apply to each you place the 'Filter array' and the condition.

Now on the left side of the Filter array condition rule you just need to add the following WDL expression...

items('Apply_to_each_filename')

 

Now, if you add 'SEnd an email' on the 'false' branch of the Condition action block, you will receive an email per filename not found.

But you can add an 'initialize variable' at the top of your flow, let's call it 'NotFoundFileNamesArray', type Array, value empty. And... on the 'false' branch of the Condition action block, you can add an Append to array' action block, and add to 'NotFoundFileNamesArray' a new element by means of the following WDL expression...

 

items('Apply_to_each_filename')

 

Now, out of your 'Apply to each' you can include the 'Send an email' action block and add the array to your email body.

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Great stuff, that solution is exactly what i'm looking for!

Tomorrow i'll try to build it in my flow, probably run into some problems but for now i'll accept as solution, cheers

Hello again, 

 

I think i'm quite close to solving it, i tried following your instructions and created the following:

 

i initialized variable at the top:

Kryptic_1-1600766882887.png

 

 

I added the following after the 'LIST FILES IN FOLDER' step:

Kryptic_0-1600766851290.png

 

I don't think this is entirely correct, 

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

PA Survey Carousel Image.png

We want to hear from you!

If you are a small business ISV/Reseller, share your thoughts with our research team.

Users online (2,896)