Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Delete all files older than two days, except the ones beginning with a specific string

It's not possible with WinSCP scripting.
But you do it with WinSCP .NET assembly from a PowerShell script.
https://winscp.net/eng/docs/library_powershell

Here is an example that does almost what you need:
https://stackoverflow.com/q/38616995/850848#38617996
You just need to add a file name test, like:
$oldFiles =
    $directoryInfo.Files |
    Where-Object { -Not $_.IsDirectory } |
    Where-Object { $_.LastWriteTime -lt $limit } |
    Where-Object { $_.Name -notlike "database*" }

(untested)
jgolinuc

Delete all files older than two days, except the ones beginning with a specific string

Hi,

I'm trying to delete all files older than two days, except the one beginning with "database*".

I was going with
rm *<2D|database*
, but no sucess, so I tried
rm *|database*<2D
but still not working.
I'm trying also with
ls
instead of
rm
to display the results, and as soon as I use the exclude pipe
|
I get a no result match.

How should I do this ?

I'm running the script through a .bat file with the following code

"C:\Program Files (x86)\WinSCP\WinSCP.com" ^

  /log="C:\Scripts\logs\%~1.log" /ini=nul ^
  /command ^
    "open ftp://user:pass@exemple.com/ -rawsettings ProxyPort=0" ^
    "cd /default/%~1/" ^
    "rm database*<30D" ^
    "rm *|database*<2D" ^
    "rm *<1K" ^
    "exit"


The goal is to delete all database files older than 30 days, then delete everything else older than 2 days and finally delete all files smaller than 1KB.

Thanks for the help.

Regards,

Joel