Get-ChildItem equivalent of DIR /X

2019-07-02 01:13发布

How do I show a directory listing in 8.3 notation in PowerShell?

3条回答
爷的心禁止访问
2楼-- · 2019-07-02 01:50

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.

查看更多
叛逆
3楼-- · 2019-07-02 02:05

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
    }    
}
查看更多
Explosion°爆炸
4楼-- · 2019-07-02 02:06

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
查看更多
登录 后发表回答