如何在PowerShell中以8.3表示法显示目录列表?
最佳答案
您可以使用WMI:
Get-ChildItem | ForEach-Object{
$class = if($_.PSIsContainer) {"Win32_Directory"} else {"CIM_DataFile"}
Get-WMIObject $class -Filter "Name = '$($_.FullName -replace '\\','\\')'" | Select-Object -ExpandProperty EightDotThreeFileName
}
或Scripting.FileSystemObject com对象:
$fso = New-Object -ComObject Scripting.FileSystemObject
Get-ChildItem | ForEach-Object{
if($_.PSIsContainer)
{
$fso.GetFolder($_.FullName).ShortPath
}
else
{
$fso.GetFile($_.FullName).ShortPath
}
}
关于windows - 相当于DIR/X的Get-ChildItem,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16995359/