Powershell 列目录是否为空?
我认为申请替换路径将适用于:Powershell 列目录是否为空?,powershell,Powershell,我认为申请替换路径将适用于: $folder = 'C:\test' $List = Get-ChildItem $folder -Recurse | Sort-Object -Property LastWriteTime $List | Format-Table name, LastWriteTime, @{Label="Directory"; Expression={$_.Directory.Replace($folder, "")}} 相反,我在目录列中什么也得不到,而我应该得
$folder = 'C:\test'
$List = Get-ChildItem $folder -Recurse | Sort-Object -Property LastWriteTime
$List | Format-Table name, LastWriteTime, @{Label="Directory"; Expression={$_.Directory.Replace($folder, "")}}
相反,我在目录列中什么也得不到,而我应该得到
\子文件夹\
因为文件都在里面
c:\test\子文件夹
名称LastWriteTime目录
---- ------------- ---------
test.1.png 2018年7月21日晚上10:20:44
test.2.png 2018年7月21日晚上10:21:16
test.3.png 2018年7月21日晚上10:21:43
子文件夹2018年10月9日下午6:53:28
Get ChildItem
的目录成员是System.IO.DirectoryInfo
。它有一个成员,Name
,可以使用
PS H:\clan\2018-09-05> (Get-ChildItem).Directory | Get-Member
TypeName: System.IO.DirectoryInfo
尝试使用:
Get-ChildItem | ForEach-Object { $_.Directory.Name }
Get ChildItem
的目录成员是System.IO.DirectoryInfo
。它有一个成员,Name
,可以使用
PS H:\clan\2018-09-05> (Get-ChildItem).Directory | Get-Member
TypeName: System.IO.DirectoryInfo
尝试使用:
Get-ChildItem | ForEach-Object { $_.Directory.Name }
使用$..DirectoryName
@LotPings感谢它的工作:)使用$..DirectoryName
@LotPings感谢它的工作:)