Recursive get and delete files (but not the directories !)

Advertisement

lennelei
Joined:
Posts:
2
Location:
France

Recursive get and delete files (but not the directories !)

Hi,

I have a FTP server with the following directories:

/OUT/DIR1/
/OUT/DIR2/
/OUT/DIR3/    

Within each directory, I may have one or more file nammed "FILExxxxxxx.txt"

I wanted to write a WinSCP command to retrieve all files and then delete them, but without trying to delete the directories.

I first tried with this:
> winSCP.com /command "option batch abort" "option confirm off" "open SESSION" "cd /OUT/" "get -transfer=binary -delete -filemask=FILE*.txt * .\" "close" "exit"    
If I don't use -delete option, it works, however, with the -delete option, it fails as it try to delete /OUT/DIR1 (and the user has no right for this hopefully).

I then tried with multiple filemask combination without success:
> winSCP.com /command "option batch abort" "option confirm off" "open SESSION" "cd /OUT/" "get -transfer=binary -delete -filemask=/OUT/*/FILE*.txt * .\" "close" "exit"
> winSCP.com /command "option batch abort" "option confirm off" "open SESSION" "cd /OUT/" "get -transfer=binary -delete -filemask=FILE*.txt;/OUT/*/ *" "close" "exit"
> winSCP.com /command "option batch abort" "option confirm off" "open SESSION" "cd /OUT/" "get -transfer=binary -delete -filemask=/OUT/*/FILE*.txt *" "close" "exit"    

WinSCP always tries to remove directories :(

Any way to achieve this? I've seen in an old post that recursive delete was not supported by WinSCP in 2012 but maybe today... ? :D

Thanks!

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
27,253
Location:
Prague, Czechia

Re: Recursive get and delete files (but not the directories !)

This should work:
winSCP.com /command "open SESSION" "get -transfer=binary -delete -filemask=/OUT/DIR1/FILE*.txt .\DIR1\" "exit"
winSCP.com /command "open SESSION" "get -transfer=binary -delete -filemask=/OUT/DIR2/FILE*.txt .\DIR2\" "exit"
winSCP.com /command "open SESSION" "get -transfer=binary -delete -filemask=/OUT/DIR3/FILE*.txt .\DIR3\" "exit"    

Reply with quote

lennelei
Joined:
Posts:
2
Location:
France

Hi,

thank you for the suggestion, actually, I wanted to avoid having to declare each directories as they might be subject to change.

I manage to make it work by using "option batch continue" instead, but it's not very nice ;)

Too bad that the delete option doesn't use the filemask as well! Maybe it could be a new feature?

Thanks again.

Regards.

Alexis

Reply with quote

Advertisement

You can post new topics in this forum