【发布时间】:2019-03-25 15:02:42
【问题描述】:
我有一个带有子目录的测试目录:
C:\test
- test1
- test-1-1
- DIR1
- 1.0
- test-1-2
- DIR2 => Latest modified sub dir
- 1.1
- test2
- test-2-1
- DIR1 => Latest modified sub dir
- 1.3
- test-2-2
- DIR1
- 1.2
可以为test中的每个子目录输出最新修改的子目录的名称和版本。假设 DIR1 或 DIR2 可以是任何名称。
最终的看法更像:
test-1-2 1.1
test-2-1 1.3
目前我能得到的唯一输出是只有最新的test*-*-* 而不是 DIR*:
gci 'C:\test' |where { $_.psiscontainer } |foreach { get-childitem $_.name |sort creationtime | select -expand name -last 1 }
PS C:\test> gci 'C:\test' |where { $_.psiscontainer } |foreach { get-childitem $_.name |sort creationtime | select -expand name -last 1 }
test-1-2
test-2-1
【问题讨论】:
-
[1] 您所需输出的示例与您描述的不匹配。以下缺少
DIR1>>test-2-1 1.3-Directory 参数用于Get-ChildItem。 ///// [3]一旦你有了一个目录,你可以使用.Parent属性会给你包含那个项目的目录。 -
一般来说,我想输出版本目录,在那个案例 DIR* 中的父目录是最后修改的,并且只显示那个版本而不是全部。所以在第一个例子中应该只输出
test-1-2 1.1 -
ok ---- 但是您一直将
DIR*称为最新的...然后只显示该最新目录的父级和子级。这不是你一直在描述的。 [皱眉]
标签: powershell