批处理文件来删除文件N多天的 [英] Batch file to delete files older than N days
问题描述
我要寻找一种方式来删除所有文件超过7天在MS-DOS批处理文件。我在网上搜索周围,并发现了一些例子数百code的线,和其他人需要安装额外的命令行工具来完成任务。
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.
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
安装在您的机器上,从任何的%WINDIR%\\ SYSTEM32 \\ ;> Windows Server 2003的您的Windows群组。这是可能的,因为EXE为Windows Server 2003和Windows&NBSP之间完全兼容。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&NBSP; 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屋!