使用以下代码行:
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行的文件。
建议?
答案 0 :(得分:8)
get-childitem -Path d:\scripts –recurse |
where-object {$_.lastwritetime -gt (get-date).addDays(-1)} |
where-object {-not $_.PSIsContainer} |
Foreach-Object { $_.FullName }
$_.PSIsContainer
对于文件夹是正确的,允许额外的where-object过滤掉它们。
答案 1 :(得分:2)
试试这个:
dir d:\scripts –recurse | where {!$_.PSIsContainer -AND $_.lastwritetime -gt (get-date).addDays(-1)} | foreach { $_.FullName }
答案 2 :(得分:0)
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 }
答案 3 :(得分:0)
列出所有子目录中的所有文件,并按LastWriteTime排序(末尾最新写入):
Get-ChildItem -Recurse | Sort-Object -Property LastWriteTime | Select-Object LastWriteTime,FullName