问题
I want to delete
extensionless files older than 7
days whose names end with _C
.
Example files:
B_C_A1_C B_C_A2_C B_C_A3_A test.txt
My code:
SET mypath=%cd%\downloads
ForFiles /p %mypath% /d -7 /c "cmd /c del /q %mypath%\*_C
When I execute the code, it deletes all files which contains _C
, but I want to delete only files which end with _C
and are older than 7
days.
How can I fix this?
回答1:
For more information about the forfiles documention, see Batch file to delete files older than N days.
The wildcard expression *_C
selects any files which end with _C
, regardless of whether it has an extension.
The final code is insanely complicated:
forfiles /p "%cd%" /m *_C /C "cmd /c \"echo @file^|find \".\" ^|^| del @path\""
Using *_C
will select the following:
anything without periods_C
It will NOT select the following:
any.thing_C
anything.txt._C
anything containing periods_C
来源:https://stackoverflow.com/questions/60266385/how-to-delete-files-end-with-a-substring-and-older-than-n-days