根据子文件夹的最后修改日期对文件夹进行排序
Sort folders according last modified date of subfolders
我有一个 windows 网络共享,其中有 1000 多个文件夹,这些文件夹也有子文件夹。
我想删除几年没修改过的文件夹
当我在 "date modified" 之后在文件资源管理器中排序时,它会正确地对父文件夹进行排序。
但不考虑子文件夹中的更改。
我尝试创建一个 PowerShell 脚本,根据文件夹或子文件夹中的最后写入时间对网络共享上的所有文件夹进行排序。
不幸的是,在当前状态下,它一遍又一遍地只列出最新修改的文件夹。
示例:
Get-ChildItem c:\tmp -Directory | ForEach-Object { Get-ChildItem -Directory -Recurse | Sort {$_.LastWriteTime} -Descending | Select {$_.FullName}, {$_.LastWriteTime} -First 1 }
有人可以帮忙吗?
我想你想要"the most recent LastWriteTime of any sub-file/folder",也就是
Get-ChildItem -Recurse -Force |
Sort-Object -Property LastWriteTime |
Select-Object -Last 1 -ExpandProperty LastWriteTime
然后你可以这样写:
Get-ChildItem -Path 'c:\test' -Directory |
Select-Object -Property Name, @{Label='LastWriteInside'; Expression={
($_ | Get-ChildItem -Recurse -Force|
Sort-object -property LastWriteTime|
Select-Object -expandproperty lastwritetime -Last 1)
}} |
Sort-Object -Property LastWriteInside
我有一个 windows 网络共享,其中有 1000 多个文件夹,这些文件夹也有子文件夹。
我想删除几年没修改过的文件夹
当我在 "date modified" 之后在文件资源管理器中排序时,它会正确地对父文件夹进行排序。
但不考虑子文件夹中的更改。
我尝试创建一个 PowerShell 脚本,根据文件夹或子文件夹中的最后写入时间对网络共享上的所有文件夹进行排序。
不幸的是,在当前状态下,它一遍又一遍地只列出最新修改的文件夹。
示例:
Get-ChildItem c:\tmp -Directory | ForEach-Object { Get-ChildItem -Directory -Recurse | Sort {$_.LastWriteTime} -Descending | Select {$_.FullName}, {$_.LastWriteTime} -First 1 }
有人可以帮忙吗?
我想你想要"the most recent LastWriteTime of any sub-file/folder",也就是
Get-ChildItem -Recurse -Force |
Sort-Object -Property LastWriteTime |
Select-Object -Last 1 -ExpandProperty LastWriteTime
然后你可以这样写:
Get-ChildItem -Path 'c:\test' -Directory |
Select-Object -Property Name, @{Label='LastWriteInside'; Expression={
($_ | Get-ChildItem -Recurse -Force|
Sort-object -property LastWriteTime|
Select-Object -expandproperty lastwritetime -Last 1)
}} |
Sort-Object -Property LastWriteInside