How to download all the .csv files with the file name starting with "cash" or "EFT" or "DDR"

0 votes
asked Aug 28 by Vinay (170 points)

Hi,
I need to download and delete all CSV files which have a name starting with "cash" or "EFT" or "DDR".

I have implemented download and delete for csv but not sure on how to check for the filename.

Please suggest.

Thanks,
Vinay

Applies to: Rebex SFTP

1 Answer

+1 vote
answered Aug 28 by Lukas Matyska (46,810 points)
selected Aug 28 by Vinay
 
Best answer

This can be easily done using the Rebex.IO.FileSet class:

// define FileSet
var set = new FileSet("/home/data");
set.Include("cash*.csv");
set.Include("EFT*.csv");
set.Include("DDR*.csv");

Then you can use it like this:

// download then delete
client.Download(set, @"C:\data");
client.Delete(set);

Or even in single line:

// move = after succesfull download delete file immediately
client.Download(set, @"C:\data",  TransferMethod.Move, ActionOnExistingFiles.ThrowException);
commented Aug 30 by Vinay (170 points)
Thanks, Lukas.
Another question I have is below single line download delete the file only if the download is successful?
client.Download(set, @"C:\data",  TransferMethod.Move, ActionOnExistingFiles.ThrowException);
commented Aug 30 by Lukas Matyska (46,810 points)
Yes. The proces goes like this:

for each file
  Download file
  Delete file

If Download file fails or file is skipped, the Delete file is not performed.
...