How to filter files from directory

Hi Snaplogic experts,

iam struggling with one task - get two files from source directory and process them (everything works fine if both files are there or one of the files is in directory)

My problem is - if both files are not presented, send an email - everything works fine if there are only two files in source directory (directory browser returns me 0 documents) - snaplogic will send an email that files are not there.problem is, if in source directory are another files, or folders - directory browser never retrieve 0 documents (logically).

So i used filter snap - but if there is no output from filter, pipeline ends and send nothing.

My question is: how to check source directory if files test1.csv and test2.csv are there (there are more files - test3.csv inovice.pdf etc) and if files are not there send an email ?

thank you

Simplest thing whould be to use the glob pattern to filter the files you want the directory browser to collect.

Link to Directory Browser documentation:
Directory Browser

Other thing you could try is to add a Gate snap after the filter on your current design. The gate snap will continue even if you don’t have anything on input.

Be careful though, if your files volume increases over time the gate snap can be dangerous since it puts everything that it’s received on input into an array.

2 Likes

You can use the filter function of the Directory Browser snap to only look for specific file names. In your case of matching test1.csv and test2.csv, but not matching test3.csv or any other value, you could use the filter expression :

test[1-2].csv

This will search the directory for all files with the value of test1.csv and test2.csv, but no other values. If there are multiple files with the test1.csv/test2.csv name, then all those files will be returned.

2 Likes

That looks promising …looks like ive used names with same name (test) …but how to build expression if one file is “mama mia.csv” and another one is “snaplogic.csv”?

is there a chance to use regex? to solve it with something like this?

^mamma mia.csv$|^snaplogic.csv$

The Directory Browser uses GLOB, not Regex, but you can do similar searches. Multiple patterns can be used. They must be contained in brackets. For example the following will return ‘mamma mia.csv’ and ‘snaplogic.csv’:

{mamma mia.csv, snaplogic.csv}

Check the SnapLogic documentation here for the Directory Browser file filter -here-.

@SL12345 You can try below option -

  1. For extracting file {test1,test2}.csv … If want to pull all file name with test try {test}.csv
  2. For error scenario -
    Make sure you dis-select that option. Then use router-
    $.hasPath(‘Name’) → for success
    !$.hasPath(‘Name’) → for failure

1 Like

i dont know why but {mamma mia.csv} didnt work, i had to use {mamma%20mia.csv} in order to encode (empty) space between words