FORFILES 日期 -after-(cmd 文件中的日期计算) [英] FORFILES date -after- (date calc in cmd file)

查看:34
本文介绍了FORFILES 日期 -after-(cmd 文件中的日期计算)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 cmd 文件中使用 FORFILES,在给定日期之后到今天"对所有文件进行操作.我可以使用类似 forfiles/d +07/10/2013/c "cmd/c echo @fname" 之类的东西来处理 7/10/13 之后的所有事情,但我想要的只是可以从今天"之前的 90 天开始计算.

I'd like to use FORFILES in a cmd file, to act on all files after a given date thru "today". I can use something like forfiles /d +07/10/2013 /c "cmd /c echo @fname" to act on everything after 7/10/13, but what I want is to just be able to calculate instead from 90 days before "today".

是否有一种适用于 cmd 文件的日期计算语法,可以让我指定今天之前的 x 天"以输入 FORFILES?

Is there a syntax for the date calculation that will work in a cmd file that will let me specify "x days before today" to feed into FORFILES?

我不喜欢使用 VBS(并找到了一个可以在 VBS 中工作的代码片段),尽管我也可以为 Powershell 重新编写我的脚本,但理想情况下我想坚持使用 cmd.

I prefer to not use VBS (and found a code snippet that would work in VBS), though I could alternatively re-write my script for Powershell, but ideally I want to stick with cmd.

澄清一下,-90"会找到所有超过 90 天的文件;+90"会查找比今天之后 90 天更新的所有文件(这从根本上是无用的,因为文件很少用未来日期写入),+7/30/2013"​​会查找所有比 7/30 更新的文件/2013.我想要最后一个时间段,最好能够将天数变量传递给 CMD 文件,即在今天之前的 x 天之后",即在过去的 x 天".因此,我希望能够在 cmd 文件中计算该日期,而不是使用如上所示的硬编码日期.

To clarify, "-90" would find all files older than 90 days; "+90" would find all files newer than 90 days -after- today (which is fundamentally useless, as files are rarely written with future dates), and "+7/30/2013" will find all files newer than 7/30/2013. I want that last time period, preferably able to take a number-of-days variable passed to the CMD file, that would say "after x number of days before today", i.e. "in the last x days". So instead of using the hard-coded date as shown above, I want to be able to calculate that date within the cmd file.

推荐答案

在 PowerShell 中,您可以执行以下操作:

In PowerShell you could do something like this:

$refdate = (Get-Date).AddDays(-90)
Get-ChildItem | Where-Object {
    $_.LastWriteTime -ge $refdate
} | Select-Object -Expand Name

这篇关于FORFILES 日期 -after-(cmd 文件中的日期计算)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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