首页 > 解决方案 > Powershell - 使用 dir / GetChildItem 列出修改日期的目录

问题描述

所以目前我可以使用文件夹名称获取我的目录列表

dir -directory -name   

而且我也知道我也可以使用递归来列出子目录 谢谢三一

我想在这个列表中创建的是显示这个文件夹的日期修改值。 我查看了文档,我很难找到我假设的答案,如果它在那里,它可能是属性的一部分,但我不确定如何正确格式化它。

我所做的大多数搜索都是关于根据修改日期排除文件,而不是显示日期。

标签: powershelldirectoryget-childitem

解决方案


你可以用Select-Object和我喜欢用的Export-Csv

Get-ChildItem C:/temp -directory -recurse  | Select-Object FullName, LastWriteTime | Export-Csv -Path list_my_folders.csv -NoTypeInformation

如果您还想提取其他信息,您也可以删除该Select-Object部分,您将看到所有可以选择的列。

输出:

"FullName","LastWriteTime"
"C:\temp\save","21.11.2019 15:34:27"
"C:\temp\test","12.01.2020 05:13:24"
"C:\temp\test\002custom","14.12.2019 01:17:54"
"C:\temp\test\002normal","14.12.2019 01:31:46"
"C:\temp\test\x","13.01.2020 12:51:05"
"C:\temp\test\002normal\normal","14.12.2019 01:31:53"
"C:\temp\test\x\Neuer Ordner","13.01.2020 12:51:05"

当然你也可以不使用它Export-Csv

Get-ChildItem C:/temp -directory -recurse  | Select-Object FullName, LastWriteTime > list_my_folders.txt

但输出的格式在大多数情况下更难处理:

FullName                      LastWriteTime      
--------                      -------------      
C:\temp\save                  21.11.2019 15:34:27
C:\temp\test                  12.01.2020 05:13:24
C:\temp\test\002custom        14.12.2019 01:17:54
C:\temp\test\002normal        14.12.2019 01:31:46
C:\temp\test\x                13.01.2020 12:51:05
C:\temp\test\002normal\normal 14.12.2019 01:31:53
C:\temp\test\x\Neuer Ordner   13.01.2020 12:51:05

推荐阅读