Displaying the DOS Name: Commands and Examples
The “DOS name” usually refers to the 8.3 (short) filename used by DOS and legacy Windows systems alongside long filenames. Many commands and scripts—especially those interacting with older tools, compatibility layers, or certain filesystems—require or benefit from knowing a file’s DOS (short) name. This article shows how to view DOS names on modern Windows systems, with commands and examples you can run in Command Prompt and PowerShell.
When and why you need the DOS name
- Legacy compatibility: Older programs may accept only 8.3 filenames.
- Scripting and automation: Short names can simplify parsing in scripts that assume no spaces or long names.
- Troubleshooting: Identifying short names helps diagnose issues with file access or compatibility.
How Windows generates short (8.3) names
- Windows creates an 8.3 short name for files and folders on NTFS volumes depending on the system setting for 8.3 name creation. Administrators can disable or enable this behavior; on many modern installations, 8.3 generation is enabled on system volumes but may be disabled on others to improve performance.
Command Prompt (cmd.exe) methods
1) Using the DIR /X switch
DIR supports showing the short (DOS) name alongside the long name.
Command:
Code
dir /x
Example (output snippet):
Code
08/01/202410:12 AMPROGRA~1 Program Files 08/01/2024 10:12 AMPROGRA~2 Program Files (x86) 11/15/2025 02:05 PM 12345 REPOR~1.TXT Report.docx
- The column before the long name shows the short (8.3) name when present. If a short name isn’t generated, that column may show blanks.
2) Using FOR to get a file’s short name
The FOR command can expand the short name of a file.
Command:
Code
for %I in (“C:\path\to\My Document.docx”) do @echo %~sI
Example:
Code
C:> for %I in (“C:\Users\alice\My Document.docx”) do @echo %~sI C:\Users\alice\MYDOCU~1.DOC
- In batch files, double the percent signs: use %%I.
PowerShell methods
1) Using Get-Item and its Name properties
PowerShell exposes file system item properties, but does not directly return the 8.3 short name by default. You can call the Windows API via .NET to retrieve it.
Script (one-liner using cmd /c for simplicity):
Code
cmd /c for %I in (“C:\path\to\My Document.docx”) do @echo %~sI
- This runs the cmd FOR approach from PowerShell.
2) Using P/Invoke to call GetShortPathName (advanced)
PowerShell can call the Win32 GetShortPathName function to obtain the short path.
Script:
powershell
Add-Type -MemberDefinition @” [DllImport(”kernel32.dll”, CharSet=CharSet.Auto)] public static extern uint GetShortPathName(string lpszLongPath, System.Text.StringBuilder lpszShortPath, uint cchBuffer); “@ -Name Win32Path -Namespace Win32 function Get-ShortPath(\(path</span><span class="token" style="color: rgb(57, 58, 52);">)</span><span> </span><span class="token" style="color: rgb(57, 58, 52);">{</span><span> </span><span> </span><span class="token" style="color: rgb(54, 172, 170);">\)sb = New-Object System.Text.StringBuilder 260 [Win32.Win32Path]::GetShortPathName(\(path</span><span class="token" style="color: rgb(57, 58, 52);">,</span><span> </span><span class="token" style="color: rgb(54, 172, 170);">\)sb, \(sb</span><span class="token" style="color: rgb(57, 58, 52);">.</span><span>Capacity</span><span class="token" style="color: rgb(57, 58, 52);">)</span><span> </span><span class="token" style="color: rgb(57, 58, 52);">|</span><span> </span><span class="token" style="color: rgb(57, 58, 52);">Out-Null</span><span> </span><span> </span><span class="token" style="color: rgb(54, 172, 170);">\)sb.ToString() } Get-ShortPath “C:\Users\alice\My Document.docx”
Example output:
Code
C:\Users\alice\MYDOCU~1.DOC
- This method returns the full short path and works reliably if the short name exists.
Checking whether 8.3 name creation is enabled
Use fsutil to query the setting for a volume (requires admin):
Command:
Code
fsutil 8dot3name query C:
Example output: “` The volume state is
Leave a Reply