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

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

问题描述

我想使用FORFILES在CMD文件,一个给定的日期直通今天之后采取行动的所有文件。我可以使用类似 FORFILES / D +07/10/2013 / CCMD / C回声@fname 13年7月10日之后采取行动的一切,但什么我想是只能够从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?

我preFER不使用VBS(并发现了一个code段,将在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天-after-(这基本上是无用的,因为文件很少与将来的日期写的),而+7/30/2013​​会发现所有的文件比7/30更新/ 2013。我想这最后一段时间里,preferably能够把一个变量传递给CMD文件数的天,那会说:今天之后天前x个,在过去x天,即。因此,而不是使用硬codeD日期如上图所示,我希望能够计算出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)
gci | ? { $_.LastWriteTime -ge $refdate } | select Name

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

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