How do I show a directory listing in 8.3 notation in PowerShell?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can use WMI:
Get-ChildItem | ForEach-Object{
$class = if($_.PSIsContainer) {"Win32_Directory"} else {"CIM_DataFile"}
Get-WMIObject $class -Filter "Name = '$($_.FullName -replace '\\','\\')'" | Select-Object -ExpandProperty EightDotThreeFileName
}
Or the Scripting.FileSystemObject com object:
$fso = New-Object -ComObject Scripting.FileSystemObject
Get-ChildItem | ForEach-Object{
if($_.PSIsContainer)
{
$fso.GetFolder($_.FullName).ShortPath
}
else
{
$fso.GetFile($_.FullName).ShortPath
}
}
回答2:
If you install the PSCX module you have the Get-ShortPath
cmdlet and you can do:
dir | Get-ShortPath
or
dir | Get-ShortPath | select -expa shortpath
回答3:
You attract my attention, this is not the full answer but my way to help you :
First : have a look to how to Control 8dot3 naming in Windows 2008 and Windows 7.
Second : here is a solution to Convert path to Dos 8.3 notation using C# that you can modify or use as is in PowerShell.