batch-file - 使用 Windows 批处理文件删除所有早于今天的 *.Zip 文件
问题描述
假设您必须使用 Windows 批处理文件(not powershell
),并且想要删除.zip
当前活动目录中所有以结尾的文件。这个怎么做?
到目前为止的所有尝试都失败了:
forfiles -p "C:\temp\test" -s -m *.zip -d 1 -c "cmd /c del *.zip"
为此它说
ERROR: No files found with the specified search criteria.
解决方案
正如我在评论中所建议的那样,您的问题可以通过阅读命令的使用信息来轻松解决, (在命令提示符下输入时可用FORFILES /?
) 。
根据您的问题标准,“delete all files ending in .zip
在the current active directory
”:
您不需要使用该/P
选项,因为如使用信息中所述,“ The default folder is the current working directory (.)
”。
您的问题中没有关于当前目录的递归子目录的任何内容,因此不需要/S
" " 选项。Instructs forfiles to recurse into subdirectories
对于/D
您正在查找上次修改日期小于昨天的文件的选项,即 " the current date minus "dd" days
",/D -1
。
因为要删除当前目录中的文件,所以不需要使用 " Full path of the file
", @path
,所以你需要的是 " The name of the file
", @file
。
FORFILES /M *.zip /D -1 /C "CMD /C DEL @file"
推荐阅读
- java - 如何更新数据库值
- php - 部署者:从没有存储库的本地机器部署
- r - 从 yahoo Finance 导入股票数据后复制 R 中的第 0 列(日期列)
- angular - Angular 8 代理和 oauth2 400 错误请求
- angular - @rxweb/reactive-form-validators 基于装饰器的验证在表单中消失了翻译器
- javascript - 我可以使用 JQUERY AJAX 调用另一个 JS 文件并从中返回数据(此处为:字符串)吗?
- java - 为包含路径变量的 url 禁用 spring 安全性
- c++ - 在编译期间操作字符串的 C/C++ 宏
- reactjs - 如何在 react/redux 应用程序中正确获取数据?
- r - R Shiny:根据用户输入切换数据集