【发布时间】:2009-05-06 02:15:48
【问题描述】:
以下脚本将删除指定目录中超过 14 天的文件,并写入 .txt 并附上已删除的路径和文件(在另一个论坛上找到此脚本..感谢 shay):
dir c:\tmp -recurse | where {!$_.PsIsContainer -AND $_.lastWriteTime -lt (Get-Date).AddDays(-14) } | select LastWriteTime,@{n="Path";e={convert-path $_.PSPath}} | tee c:\oldFiles.txt | Remove-Item -force -whatif
我有 3 个问题:
- 什么是
-lt,什么是-le,什么是-gt?我什么时候使用每个 - 上面的脚本只删除文件...我怎样才能删除文件夹呢?
- 上面的脚本是基于
LastWriteTime.. 那么CreatedDate或LastAccessed时间呢?
【问题讨论】:
-
我认为 {!$.PsIsContainer -AND $.lastWriteTime 应该有管道变量的下划线,即 {!$_.PsIsContainer -AND $_.lastWriteTime
标签: c# powershell delete-file