批量文件删除N天以前的文件 [英] Batch file to delete files older than N days

查看:144
本文介绍了批量文件删除N天以前的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来删除MS-DOS批处理文件中超过7天的所有文件。我在网上搜索过,发现了几百行代码的例子,还有一些需要安装额外的命令行工具来完成这个任务。

I am looking for a way to delete all files older than 7 days in an MS-DOS batch file. I've searched around the web, and found some examples with hundreds of lines of code, and others that required installing extra command line utilities to accomplish the task.

类似的东西可以在在BASH中完成几行代码。看来,对于Windows中的批处理文件,可以做到至少远程简单的事情。我正在寻找一个工作在标准的Windows命令提示符,没有任何额外的实用程序的解决方案。请不要使用PowerShell或Cygwin。

Similar things can be done in BASH in just a couple lines of code. It seems that something at least remotely easy could be done for batch files in Windows. I'm looking for a solution that works in a standard Windows command prompt, without any extra utilities. Please no PowerShell or Cygwin either.

推荐答案

享受:

forfiles -p "C:\what\ever" -s -m *.* -d <number of days> -c "cmd /c del @path"

请参阅 forfile文档了解详情。

有关更多的好东西, Windows XP命令行的AZ索引

For more goodies, refer to An A-Z Index of the Windows XP command line.

如果您的计算机上没有安装 forfiles ,请从任何 Windows Server 2003 导入您的Windows XP计算机%WinDir%\system32\ 。这是可能的,因为EXE在Windows Server 2003和Windows XP之间完全兼容。

If you don't have forfiles installed on your machine, copy it from any Windows Server 2003 to your Windows XP machine at %WinDir%\system32\. This is possible since the EXE is fully compatible between Windows Server 2003 and Windows XP.

Windows和Windows Server的早期版本默认已安装。

Later versions of Windows and Windows Server have it installed by default.

对于Windows 7:

For Windows 7:

语法已经改变了一点。因此,更新的命令是:

The syntax has changed a little. Therefore the updated command is:

forfiles -p "C:\what\ever" -s -m *.* /D -<number of days> /C "cmd /c del @path"

这篇关于批量文件删除N天以前的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆