批处理文件删除超过 N 小时或分钟的文件 [英] Batch file to delete files older than N hours or minutes

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

问题描述

我看到了这个 - 批处理文件以删除早于N天

但是我如何删除超过 N 小时或分钟的文件?

But how can I delete files older than N hours or minutes?

谢谢.

推荐答案

这里的解决方案都不适合我.它们是非常创新的解决方案,第一个 (.net/FileTimeFilerJS.bat [sic]) 实际上对我有用过一次.然而,当我试图在另一个文件夹上调用它时,它只是崩溃了.我尝试了第二个(jscript/FileTimeFilterJs.bat),但它没有成功删除超过一小时的所有文件.

Neither of the solutions here worked for me. They are very innovative solutions, and the first one (.net/FileTimeFilerJS.bat [sic]) actually worked once for me. When I tried to call it on another folder, however, it simply crashed. I tried the second one (jscript/FileTimeFilterJs.bat), but it did not successfully delete all files older than one hour.

我的解决方案需要一个可执行文件,但我发现它对我来说是最好的解决方案.

My solution requires an executable, but I found it was the best solution for me.

我从 GnuWin32 下载了 FindUtils,并提取了 3 个文件(您必须下载下面的两个 zip 文件):libintl3.dll、libiconv2.dll 和 find.exe(它们的总大小约为 1MB).我将 find.exe 重命名为 gnu_find.exe 只是为了避免 Windows FIND 命令.

I downloaded FindUtils from GnuWin32, and extracted 3 files (you have to download the two zips below): libintl3.dll, libiconv2.dll, and find.exe (combined they are about 1MB in size). I rename find.exe to gnu_find.exe just to avoid the Windows FIND command.

然后,您可以运行漂亮的 GNU 命令(以下命令适用于环境变量 %fldr% 指定的文件夹中超过 120 分钟的所有 zip 文件):

Then, you can run the beautiful GNU command (below command is for all zip files older than 120 minutes in folder specified by environment variable %fldr%):

gnu_find %fldr% -name *[.:]zip -type f -mmin +120 -delete

我使用 *[.:]zip 代替 *.zip,因为 Windows 7+ 会在 find 使用它之前扩展 *.zip.

Instead of *.zip, I use *[.:]zip, because Windows 7+ will expand the *.zip before find can use it.

查找实用工具箱

查找Utils deps

这篇关于批处理文件删除超过 N 小时或分钟的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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