Post a reply

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

traveller198

Remove all files in all Sub Folders named *.trn older than 7 days

Hi Everyone,

I have the following batch script I am using to try and delete all .trn files from all subfolders of a specific directory:
@echo off
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="PATH\winscp.log" /logsize=5*100M /ini=nul ^
  /command ^
    "open sftp://USER:PASS@SERVER/ -hostkey=""HOSTKEY""" ^
    "cd /PATH TO TOP LEVEL DIRECTORY/" ^
    "rm *.trn<7D" ^
    "close" ^
    "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
 
exit /b %WINSCP_RESULT%

When I run the script nothing is deleted and the logs show:

Script: No file matching '*.trn<7D' found.

There are no .trn files in the root folder the script CD's in to, but there are many older than 7 days, 1 or more sub folders below. How can I get the script looking in all sub folders?