[英]Powershell get list of sub folders and number of files in each in a table format
[英]Powershell get list of all folders and files modified in the last 4 months in ascending order
我尝试了以下代码来获取按上次修改日期排序的文件和文件夹列表:
Get-ChildItem -Force -Recurse -File -Path "E:\ES" -ErrorAction SilentlyContinue | Where-Object { $_.CreationTime.Date -lt (Get-Date).Date } | Sort CreationTime -Descending | Format-Table -Wrap
是否可以编辑此代码,使文件夹和文件列表仅限于过去 4 个月内修改过的内容?
先感谢您! 你们对回答我以前的所有问题都非常有帮助!
基本上,你需要改变的是:
(Get-Date).Date
您提供今天午夜(Get-Date).AddMonths(-4).Date
, (Get-Date).AddMonths(-4).Date
您提供 4 个月前午夜的日期)-ge
将为您提供大于或等于 4 个月前日期的所有日期)LastWriteTime
是文件上次修改的日期。 CreationTime
也可以是文件复制到其最终目的地的日期,不一定是文件首次创建的实际日期。$refDate = (Get-Date).AddMonths(-4).Date # 4 months ago at midnight
Get-ChildItem -Path "E:\ES" -Force -Recurse -File -ErrorAction SilentlyContinue |
Where-Object { $_.LastWriteTime -ge $refDate } |
Sort-Object LastWriteTime -Descending |
Format-Table -Wrap
以上将仅列出文件。 如果您还想要目录,只需删除-File
开关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.