![](/img/trans.png)
[英]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.