powershell - 我输入的 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"
?
解决方案
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)}
这将获得一个目录列表并选择创建时间大于或等于五天前日期的文件。
推荐阅读
- php - remove_submenu_page('woocommerce', 'wc-admin'); 功能不删除仪表板
- flutter - 是否可以在 Flutter 中向 Future 发送查询类型的 url?
- sql - 减去日期时使用 CTE 的 Postgres SQL
- python - 使用Python中根节点的小写属性抛出的ElementTree进行XML解析
- javascript - 我们可以在点击时删除 HTML 元素的边框吗?但保持边界为焦点
- python - 在 Python 中比较 String 和 Naive 格式的时间
- c# - C# - 查找特定值是否在列表中具有重复项
- node.js - 如何将图像上传到 KeystoneJS GraphQL 端点?
- r - 为不同的数据集Winsorizing相同的变量
- mysql - 前台不发送任何内容