Skip to content

Dear Internet Explorer user: Your browser is no longer supported

Please switch to a modern browser such as Microsoft Edge, Mozilla Firefox or Google Chrome to view this website's content.

DOS 8.3 short paths via PowerShell

Use this PowerShell script to discover the DOS 8.3 path name for any selected folder in Windows.

Sometimes in programming, there is a need to return the short path name of a folder. The following PowerShell script will return the short path name of a selected directory in Windows.

In PowerShell, simply cd to the directory that you wish to derive the DOS 8.3 path name for, then use the following code:

New-Item 0.txt -type file | Out-Null #Creates 0.txt

$path = (dir 0.txt).FullName #Returns full path name of file

$object = New-Object -ComObject Scripting.FileSystemObject
$output = $object.GetFile($path)
$output.shortpath.trim("0.txt") | Out-Null #Generates 8.3 short file path output

Write-Host "`n`n The short path of this directory is" $output.shortpath.trim("0.txt") #Writes output

Remove-Item 0.txt #Deletes 0.txt

The script works by making a new file (called 0.txt) in the folder and deriving the DOS 8.3 file name for that file. The path then has the file name removed (because we’re interested in the directory) and the new file is deleted again.

Screen capture of PowerShell ISE

PowerShell ISE displaying the code that reveals the DOS 8.3 short path of a directory

The equivalent code is for %I in (.) do echo %~sI when using the Microsoft Command Prompt.

Screen capture of Windows Command Prompt

The Windows Command Prompt showing the use of a command to reveal the DOS 8.3 short path.



2 responses to “DOS 8.3 short paths via PowerShell”

On 16 March 2019, tnt wrote: Hyperlink chain icon

Slightly more brief:

$object = New-Object -ComObject Scripting.FileSystemObject
$output = $object.GetFolder($PWD)
Write-Host "`n`n The short path of this directory is" $output.shortpath


Have Your Say

The following HTML is permitted:
<a href="" title=""> <b> <blockquote cite=""> <code> <em> <i> <q cite=""> <strike> <strong>

Comments will be published subject to the Editorial Policy.