首页 > 解决方案 > 我输入的 forfiles -d 值有什么问题?

问题描述

每当我输入:

forfiles /d +10/20/2019 /c "cmd /c echo @FILE 最近 5 天"

我收到一条错误消息,提示时间设置错误。当我将它更改为 -50 或 -100 之类的东西时,它的工作原理就是为这些时间显示正确的文件。我似乎遵循 mm/dd/year 的格式...?我不知道出了什么问题。我想列出过去 5 天内制作的所有文件。所以我基本上无法让速记日期系统正常工作。如果我将 /d 移动到 cmd 值之后,那么 " 也会像 ..

forfiles /c "cmd /c echo @FILE 最近 5 天 /d +10/20/2019"

?

标签: powershell

解决方案


forfiles是一个主要与 cmd 一起使用的可执行文件。

问题在于日期格式。根据forfiles /?帮助,遵循“dd.MM.yyyy”格式。这可能取决于系统区域设置,因此请查看您的安装帮助;我的 说:

/D    date          Selects files with a last modified date greater
                    than or equal to (+), or less than or equal to
                    (-), the specified date using the
                    "dd.MM.yyyy" format; or selects files with a
                    last modified date greater than or equal to (+)
                    the current date plus "dd" days, or less than or
                    equal to (-) the current date minus "dd" days. A
                    valid "dd" number of days can be any number in
                    the range of 0 - 32768.
                    "+" is taken as default sign if not specified.

至于 Powershell 解决方案,使用Get-ChildItem和过滤基于CreationDate,像这样

Get-ChildItem c:\temp | ? {$_.CreationTime -ge (Get-Date).AddDays(-5)}

这将获得一个目录列表并选择创建时间大于或等于五天前日期的文件。


推荐阅读