Powershell 2 选择并选择按创建日期显示文件名
我正在尝试查找名称为 VAT*.xls
且创建日期小于 6 个月前的文件的所有实例。我已经尝试过:
dir c:\vat*.xls -r | ? {($now -$_.lastwritetime).days -lt 300}
并且
gci c:\vat*.xls -r | ? {($now -$_.lastwritetime).days -lt 300}
我知道有一个日期为 2010 年 4 月 1 日的文件 VAT0210.xls
,但两个查询都没有给我答案。应该是什么?
I'm trying to find all instances of files with names like VAT*.xls
where the creation date is less than 6 months ago. I have tried:
dir c:\vat*.xls -r | ? {($now -$_.lastwritetime).days -lt 300}
and
gci c:\vat*.xls -r | ? {($now -$_.lastwritetime).days -lt 300}
I know there is a file VAT0210.xls
dated 1 April 2010 but neither query gives me that answer. What should it be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对你的问题有点困惑。首先,您写下您想要获取创建日期小于六个月前的文件,然后与
LastWriteTime
进行比较。然后你说你想要六个月,但与300天相比。我在这里关注你的散文,希望这是正确的。
如您所见,这相当简单。用别名重写:
如果我最初对您的意图的猜测不正确,请随意调整代码 - 现在应该很简单了。
I'm slightly confused from your question. First you write that you want to get files where the creation date is less than six months ago, then you compare with
LastWriteTime
. And then you say you want six months but compare with 300 days.I'm following your prose here in the hope that was the correct one.
As you can see, it's fairly straightforward. Rewritten with aliases:
If my initial guess as for your intentions was incorrect, feel free to adapt the code – should be trivial now.