Delete file older than X days using file name

Advertisement

john111
Guest

Delete file older than X days using file name

Hi, im new in scripting. My purpose is want make a script that can delete file automatically for example (older than 2 month) but using file name because my file name already recorded as date
(XXXX_XX-MM-DD-YYYY-XXXXXXXX.zip) due my file modified date sometimes not correct.

Below are my script, can help me check what is the problem?

"C:\Program Files (x86)\WinSCP\WinSCP.com" /ini=nul /log="C:\Users\xxxx\xxxx\Log\ftp !M !D !Y.log" /command ^
    "open ftp://user:pass@example.com/" ^
    rm -filemask="*<30D=xxxx_xx-%TIMESTAMP#mm-dd-yyyy%-xxxxxxx.zip"
    "exit"

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,567
Location:
Prague, Czechia

Re: Delete file older than X days using file name

You cannot select files older then certain timestamps by timestamp in their name using a simple file mask. You can only select all files for a specific date like:
rm XXXX_XX-%TIMESTAMP-30D#mm-dd-yyyy%-XXXXXXXX.zip

If you need to delete even files with older dates, you need to use PowerShell:
https://stackoverflow.com/q/49656000/850848

Reply with quote

john111
Guest

Re: Delete file older than X days using file name

that code works but i want to delete file for example older than 30day+
same function like
*<30D

The code that u give only delete folder older than 30days ONLY.

Please advise. Thanks

Reply with quote

Advertisement

You can post new topics in this forum