如何删除文件以子字符串结尾且早于N天 [英] How to delete files end with a substring and older than N days
本文介绍了如何删除文件以子字符串结尾且早于N天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要delete
个以_C
结尾的7
天之前的无扩展名文件.
I want to delete
extensionless files older than 7
days whose names end with _C
.
示例文件:
B_C_A1_C
B_C_A2_C
B_C_A3_A
test.txt
我的代码:
SET mypath=%cd%\downloads
ForFiles /p %mypath% /d -7 /c "cmd /c del /q %mypath%\*_C
执行代码时,它会删除所有包含_C
的文件,但是我只想删除以_C
结尾且早于7
天的文件.
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.
我该如何解决?
推荐答案
通配符表达式*_C
选择任何以_C
结尾的文件,而不管其是否具有扩展名.
The wildcard expression *_C
selects any files which end with _C
, regardless of whether it has an extension.
最终的代码非常复杂:
forfiles /p "%cd%" /m *_C /C "cmd /c \"echo @file^|find \".\" ^|^| del @path\""
使用*_C
将选择以下内容:
anything without periods_C
它将不选择以下内容:
any.thing_C
anything.txt._C
anything containing periods_C
这篇关于如何删除文件以子字符串结尾且早于N天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文