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

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

问题描述

我看到这一点 - 批处理文件删除文件早于N天

I see this - Batch file to delete files older than N days

但我怎么可以删除文件超过N个小时或分钟旧的?

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

感谢。

推荐答案

它的挑战性要做到这一点(不受时间日期设置),即使是 WSH \\的Jscript \\ VBscript的为WSH不返回日期对象当请求的文件的日期/时间属性,但依赖于时间的设置(WMI可以使用,但是,这将击中的性能)的字符串。
我假设你已经安装了.NET框架,使任务更加容易。
这里是我的最新 (和最伟大的:))混合型工具,应该在你的情况下工作。你可以用任何你想要的名称保存它。以下是如何使用它(其名为 FileDateFilterJS.bat 在这个例子中):

Its challenging to do this (independent of time date settings) even with WSH\Jscript\VBscript as WSH does not return date object when you request the date/time properties of a file ,but a string that depends on time settings (wmi could be used but this will hit the performance). I suppose you have installed .net framework which make the task far more easier. Here's my latest (and greatest :) ) hybrid tool that should work in your case. You can save it with whatever name you want. Here's how to use it (its called FileDateFilterJS.bat in this example):

@echo off

for /f "tokens=* delims=" %%# in ('FileDateFilterJS.bat  "." -hh -5') do (
    echo deleting  "%%~f#"
    echo del /q /f "%%~f#"
)

pause

当时间是5 - -hh -5 和目录是当前的 - 。你可以删除回声删除命令。

Where the hours are 5 - -hh -5 and directory is current - "." .You can remove the echo before del command.

该脚本把我比我预期更多的时间(尽管我研究的话题,并有一些地方准备好),并没有那么重的测试,因此可能仍没有马车,free.And我想帮助信息和选项可以改善。

This script took me far more time than I've expected (despite I've researched the topic and has some parts ready) and is no so heavy tested so probably is still not buggy-free.And I suppose the help message and options could be improved.

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

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