I am new to writing windows batch code. I am trying to remove files from a folder that are older than 3 days old but are checked before deleting to make sure it deletes all matching files. For instance...
123456.html
123456.txt
123456.xxx
987654.html
987654.txt
Given the list of files, I would want the batch to locate the .xxx
files and delete it and any matching files with that file prefix when all three are older than 3 days old.
I found the following on the internet:
@ECHO Off
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=C:\Users\ad9f2p\TEST CLEANUP"
FOR /f "delims=" %%a IN (
'dir /b /a-d "%sourcedir%\*" '
) DO (
SET "filename=%%a"
SET "filename=!filename:*.XXX=!"
IF "!filename!"=="!filename:_=!" ECHO DEL "%sourcedir%\%%a"
)
Pause
GOTO :EOF
I changed the file name suffix here to .xxx
in hopes of deleting all matching, but it echoed everything in the directory to delete. It should have left the 987654 files alone.