cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pebcak
Regular Visitor

match on partial name, or use array for endswith string

Situation is a remote SFTP server that has a set of files created daily.


The file names in the server are along the lines of

 

external-vendor-202021041901file1.csv
external-vendor-202021041901file121041901.csv
external-vendor-20202104190120longerfilename2.csv
external-vendor-20202104190120longerfilename2-21041901.csv
external-vendor-202021041901-daily-file.csv
external-vendor-202021041901-daily-file-2104190114.csv

 

I do not control the file name creation, specifically the filename prefix or suffix, however I do have a fairly simple set of rules, to fit with the above filenames, I have three desired filenames.

file1.csv
longerfilename2.csv
daily-file.csv

 

From the files on the SFTP server, I'm only interested in the ones where the filename can do a partial match with the filename with extension, so from the 6 filenames, I'm only interested in

 

external-vendor-202021041901file1.csv

external-vendor-20202104190120longerfilename2.csv
external-vendor-202021041901-daily-file.csv

 

These files will then be created on the destination with the name from the array, and the contents from the SFTP server, so in action, source filename external-vendor-202021041901file1.csv to destination filename file1.csv (overwriting the previous file).

 

(yes, I know this is a broken process, I just need to get rid of the SFTP client that currently runs it)

 

As the file prefixes are not all the same length (and can be changed), splitting the filename from the beginning of the name would not work

 

As the basis for a flow I have the following (I have added file.txt to the test SFTP server and to the array as a "insanity check" so I can see that I can see a match)

 

  • Initialise array (Name Filenames, type array, value
    [
    "file1.csv",
    "longerfilename2.csv",
    "daily-file.csv",
    "file.txt"
    ]
    )
  • List files in Folder SFTP
  • Select (From Body, Map Name
  • Filter, and this is where I'm lost

 

If I filter From: Filenames, Select:Output, Contains:Item the output includes file.txt, and nothing else.

 

If I change the filter to "endswith" instead of "contains", it fails endwith requires string instead of the array.

 

I'm hoping that if teh filter can work, I can then use the output of the filter in a "for each" to use the path for each file on the SFTP server to get-contents-from-path and then create file using the name from the array and the contents.

 

Is there a way of using "contains" with a partial instead of full match, or a way to feed the array into individual strings to use endswith?

 

Although it might work if a variable of type string was used for each file, and there was a endswith for each file, as there are several dozen filenames, an array would be considerably simpler to manage in the future as there would only be the the file list in the  initial array to manage.

 

All constructive suggestions welcome

1 ACCEPTED SOLUTION

Accepted Solutions
DamoBird365
Community Champion
Community Champion

Hi @pebcak 

 

You are only filtering against one value, the item that you have supplied as a variable is part of the trigger?  You must have a trigger variable called item and have set it to file.txt?

 

If you want to compare an array with an array, you need an apply to each.  

 

For each of your apply to each file name endings (you've used a variable, i've used a compose), you want to compare each item() from the array of filenames you have created (body of select) (i've used get files, but have used a select like you this time) against the current item from the filenames array.

 

DamoBird365_1-1618912829764.png

 

Each apply to each outcome will give you a filtered array where the filename matches 1 of the 4 file ending names.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here

 

 

View solution in original post

6 REPLIES 6
DamoBird365
Community Champion
Community Champion

Hi @pebcak 

 

If you have an array of file names, contains should work?  For example:

 

DamoBird365_0-1618858896566.png

 

You can extend this and use the array of end of file names in an apply to each with your array of files from FTP.  In my example I have created an array of file names from get files.

 

DamoBird365_1-1618859424104.png

The apply to each runs 4 times and will filter the array of all files and return those that contain the end of file.

 

Hope this is what you are looking for.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here

Hi @DamoBird365 

 

Thanks for your reply. Yes the first method is an option, but with several dozen file names, management changes from editing an array, to adding a new section for each new filename, and I would far prefer to be able to hand over something where only the array needs to be edited (-:

 

Your second method is roughly what I want to acheive, but the "File name with" part is only usable with SharePoint, hence using a list files in folder SFTP, then a select to just get the file names, which when I then use in the filter, I was experiencing failing to match on the contains unless the filename was an exact match.

 

I'll post some screenshots.

DamoBird365
Community Champion
Community Champion

Hi @pebcak 

 

Can you copy the array from the select to here and I will add it to a compose and try same. 


cheers

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here

HI @DamoBird365 

 

Your assistance is much appreciated.

 

We have the flow

 

FlowFlow

 

The filter in advanced mode looks like

 

filter-advanced.PNG

 

and the results when running the flow

 

results.PNG

 

Which shows that the only "contains" match is where the filename has an exact match.

 

(edited trying to have the same image size in both, both are on "Large", but show differently...)

DamoBird365
Community Champion
Community Champion

Hi @pebcak 

 

You are only filtering against one value, the item that you have supplied as a variable is part of the trigger?  You must have a trigger variable called item and have set it to file.txt?

 

If you want to compare an array with an array, you need an apply to each.  

 

For each of your apply to each file name endings (you've used a variable, i've used a compose), you want to compare each item() from the array of filenames you have created (body of select) (i've used get files, but have used a select like you this time) against the current item from the filenames array.

 

DamoBird365_1-1618912829764.png

 

Each apply to each outcome will give you a filtered array where the filename matches 1 of the 4 file ending names.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here

 

 

View solution in original post

Hi @DamoBird365 

 

Aha, I see what you mean, I'll be able to retest in the morning

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (2,698)