首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用get-children列出带有lastwritetime的文件

使用get-children列出带有lastwritetime的文件
EN

Stack Overflow用户
提问于 2010-11-09 23:51:48
回答 4查看 53K关注 0票数 3

使用以下几行代码:

代码语言:javascript
运行
复制
get-childitem -Path d:\scripts –recurse | 
where-object {$_.lastwritetime -gt (get-date).addDays(-1)} |
Foreach-Object { $_.FullName }

我得到了d:\scripts目录下时间戳不到1天的所有内容的列表。输出:

代码语言:javascript
运行
复制
D:\scripts\Data_Files
D:\scripts\Power_Shell
D:\scripts\Data_Files\BackUp_Test.txt
D:\scripts\Power_Shell\archive_test_1dayInterval.ps1
D:\scripts\Power_Shell\stop_outlook.ps1
D:\scripts\Power_Shell\test.ps1
D:\scripts\WinZip\test.wjf

问题是,文件夹(Data_Files和Power_Shell)在日期参数中有最后一次写入。我只希望输出中的文件如第3-7行所示。

有什么建议吗?

EN

回答 4

Stack Overflow用户

发布于 2010-11-10 00:38:31

代码语言:javascript
运行
复制
get-childitem -Path d:\scripts –recurse |  
    where-object {$_.lastwritetime -gt (get-date).addDays(-1)} | 
    where-object {-not $_.PSIsContainer} |
    Foreach-Object { $_.FullName } 

$_.PSIsContainer对于文件夹是真的,允许额外的where-object过滤掉它们。

票数 9
EN

Stack Overflow用户

发布于 2010-11-10 07:08:01

代码语言:javascript
运行
复制
gci d:\scripts –recurse | 
  ? { $_.Attributes -band [System.IO.FileAttributes]::Archive } |
  ? { $_.LastWriteTime -gt (Get-Date).AddDays(-1) } | 
  foreach { $_.FullName }

代码语言:javascript
运行
复制
gci d:\scripts –recurse | 
  ? { -not ($_.Attributes -band [System.IO.FileAttributes]::Directory) } |
  ? { $_.LastWriteTime -gt (Get-Date).AddDays(-1) } | 
  foreach { $_.FullName }
票数 2
EN

Stack Overflow用户

发布于 2010-11-10 20:16:00

试试这个:

代码语言:javascript
运行
复制
dir d:\scripts –recurse | where {!$_.PSIsContainer -AND $_.lastwritetime -gt (get-date).addDays(-1)} | foreach { $_.FullName }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4135624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档