使用以下几行代码:
get-childitem -Path d:\scripts –recurse |
where-object {$_.lastwritetime -gt (get-date).addDays(-1)} |
Foreach-Object { $_.FullName }
我得到了d:\scripts目录下时间戳不到1天的所有内容的列表。输出:
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行所示。
有什么建议吗?
发布于 2010-11-10 00:38:31
get-childitem -Path d:\scripts –recurse |
where-object {$_.lastwritetime -gt (get-date).addDays(-1)} |
where-object {-not $_.PSIsContainer} |
Foreach-Object { $_.FullName }
$_.PSIsContainer
对于文件夹是真的,允许额外的where-object过滤掉它们。
发布于 2010-11-10 07:08:01
gci d:\scripts –recurse |
? { $_.Attributes -band [System.IO.FileAttributes]::Archive } |
? { $_.LastWriteTime -gt (Get-Date).AddDays(-1) } |
foreach { $_.FullName }
或
gci d:\scripts –recurse |
? { -not ($_.Attributes -band [System.IO.FileAttributes]::Directory) } |
? { $_.LastWriteTime -gt (Get-Date).AddDays(-1) } |
foreach { $_.FullName }
发布于 2010-11-10 20:16:00
试试这个:
dir d:\scripts –recurse | where {!$_.PSIsContainer -AND $_.lastwritetime -gt (get-date).addDays(-1)} | foreach { $_.FullName }
https://stackoverflow.com/questions/4135624
复制相似问题