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

查看:188
本文介绍了批量文件删除超过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文档详细信息。

有关更多好处,请参阅 a href =http://www.ss64.com/nt/ =noreferrer> 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天全站免登陆