cancel
Showing results for 
Search instead for 
Did you mean: 

How to filter files from directory

SL12345
New Contributor III

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

1 ACCEPTED SOLUTION

tarena
New Contributor III

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-.

View solution in original post

6 REPLIES 6

bojanvelevski
Valued Contributor

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.

tarena
New Contributor III

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.

SL12345
New Contributor III

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$

tarena
New Contributor III

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-.