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

chr*_*ris 2 powershell powershell-2.0

使用以下代码行:

get-childitem -Path d:\scripts –recurse | 
where-object {$_.lastwritetime -gt (get-date).addDays(-1)} |
Foreach-Object { $_.FullName }
Run Code Online (Sandbox Code Playgroud)

我得到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
Run Code Online (Sandbox Code Playgroud)

这笔交易是,文件夹(Data_Files和Power_Shell)在日期参数中有最后一次写入.我只想要输出中第3-7行的文件.

建议?

ten*_*npn 8

get-childitem -Path d:\scripts –recurse |  
    where-object {$_.lastwritetime -gt (get-date).addDays(-1)} | 
    where-object {-not $_.PSIsContainer} |
    Foreach-Object { $_.FullName } 
Run Code Online (Sandbox Code Playgroud)

$_.PSIsContainer 适用于文件夹,允许额外的where-object过滤掉它们.

  • where-object {$ _.lastwritetime -gt(get-date).addDays(-1)-and -not $ _.PSIsContainer} ##如果你不需要,请不要将where-object加倍:) (3认同)