Windows批处理文件可删除X天之前的文本文件 [英] Windows Batch file to delete text files older than X days

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

问题描述

此问题已被问过,我所引用的答案与

This question has been asked before and I am referencing the same answer as Suggested here. But the thing is that this is working fine in windows 7 ultimate whereas, the same code is not working correctly in windows server 2008 R2. It deletes all the text files from the folder if it found any of the file older than specific date, whereas it doesn't do anything if it doesn't found any text file older than specific date which is correct. The command is as follows;

REM Remove text files older than 5 days
forfiles -p "E:\Backups" -s -m *.* -d -5 -c "cmd /c del E:\Backups\*.txt"

我也看到了其他帖子,但是我在其中找不到这个特殊问题.如果有人以前遇到过这个问题,或者如果我在这里做错了,请提出解决方案,谢谢.

I have seen other posts as well but I couldn't find this particular problem in them. Please suggest the solution if somebody has faced this before or if I am doing something wrong here, Thanks.

推荐答案

@path 替换 E:\ Backups \ *.txt .

forfiles -p "E:\Backups" -s -m *.* -d -5 -c "cmd /c echo del @path"

当您对自己想做的事情感到满意时,请删除 echo .有关命令中可用@variables的完整详细信息,请参见 forfiles/?. @path 的文档有些混乱. @path 返回已经引用的标准 drive:\ path \ to \ filename.ext .

When you're satisfied that does what you want, remove the echo. See forfiles /? for full details of the @variables available within the command. The documentation for @path is a little confusing. @path returns the fully qualified drive:\path\to\filename.ext, already quoted.

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

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