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)
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
Solved! Go to Solution.
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.
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
Hi @pebcak
If you have an array of file names, contains should work? For example:
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.
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.
HI @DamoBird365
Your assistance is much appreciated.
We have the flow
Flow
The filter in advanced mode looks like
and the results when running the flow
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...)
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.
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
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
Announcing a new way to share your feedback with the Power Automate Team.
Learn to digitize and optimize business processes and connect all your applications to share data in real time.
User | Count |
---|---|
72 | |
27 | |
22 | |
15 | |
13 |
User | Count |
---|---|
140 | |
42 | |
42 | |
35 | |
30 |