I need to use shortened path names for an application that I am using. For example I need C:\PROGRA~1\ as opposed to C:\Program Files. The program can't handle spaces and won't accept quoted paths (e.g. "C:\Program Files").

If it helps, I am using Windows 7. I can get access to any version since XP, if necessary.

12 Answers 12


Start, and type cmd in the run box. Start cmd, and use cd to get to the folder you are interested in:

cd \


dir /x

C:\>dir /x

13/10/2011  09:14 AM    <DIR>          DOCUME~1     Documents and Settings
13/10/2011  09:05 AM    <DIR>          PROGRA~1     Program Files
  • 1
    So you do this for every subfolder in the path?
    – endolith
    May 6, 2015 at 18:19
  • 6
    I mean how do you display the entire 8.3 path?
    – endolith
    Jan 23, 2017 at 16:04
  • 8
    @Paul This doesn't seem to work in Win10. Any ideas? Apr 17, 2017 at 3:23
  • 5
    @AHungerArtist The short file names don't necessarily exist; their creation can be turned off.
    – Hipponax43
    May 22, 2017 at 9:51
  • 1
    @AHungerArtist An alternative that I've used on occasion is to "roll your own": create a directory junction. This can be done with either the builtin MKLINK.EXE tool. or my option of choice, the Junction utility from Sysinternals: docs.microsoft.com/en-us/sysinternals/downloads/junction . Open a command prompt in the directory containing the subdirectory with spaces in its name, and enter Junction shortname "Long Name With Spaces".
    – dgnuff
    Nov 3, 2018 at 21:19

Create a bat file in some convenient directory then you could copy+paste the short path from that path.

You could just run command.com and keep doing cd commands to your current directory too.

In Windows batch scripts, %~s1 expands path parameters to short names. Create this batch file:

echo %~s1

I called mine shortNamePath.cmd and call it like this:

C:\> shortNamePath "c:\Program Files (x86)\Android\android-sdk"

Here's a version that uses the current directory if no parameter was supplied:

if '%1'=='' (%0 .) else echo %~s1

Called without parameters:

C:\Program Files (x86)\Android\android-sdk> shortNamePath

Using SET and a named variable

Windows Command Prompt has some conventions for handling variables with spaces in their values that are somewhat hard to learn and understand, especially if you have a Unix background.  You can do

SET TESTPATH=c:\Program Files (x86)\Android\android-sdk

(with no quotes), or

SET "TESTPATH=c:\Program Files (x86)\Android\android-sdk"

(note the non-intuitive placement of quotes); then

CALL :testargs "%TESTPATH%"

echo %~s1
goto :eof
  • 12
    Really useful, should be marked as answer! Feb 19, 2015 at 11:03
  • Thanks! Is it do-able using a SET command ? like SET AAA=C:\program files\what ever\another space in the middle\ to the short version
    – Li3ro
    May 20, 2015 at 13:41
  • @Li3ro I couldn't figure out SET variable command way but I got pretty close, you can see it at the bottom of the answer just needs a little fix up. I'm not into batch script programming so I don't know how.
    – SSpoke
    May 26, 2015 at 20:29
  • It is not doable this way. you need the for loop for this
    – Li3ro
    May 27, 2015 at 4:18
  • 3
    I created a ShortName.bat file with your code (added pause) into shell:sendto folder, then I can access it by right-clicking a file then SendTo->ShortName. Thanks! Oct 10, 2017 at 7:14

Here is a one liner:

cmd /c for %A in ("C:\Program Files") do @echo %~sA


  • cmd /c - Starts a new instance of the Windows command interpreter, carries out the command specified by string and then terminates
  • for %%parameter in (set) do command - Conditionally perform a command several times.
  • echo - Display messages on screen. @ symbol is the same as ECHO OFF applied to the current line only.
  • %~s - Expanded path contains short names only.


  • 3
    Nice!!! You can replace "C:\Program Files" with . to get the short name for the current directory Sep 18, 2017 at 17:22
  • 2
    When / why would you need the cmd /c?  If you’re in a Command Prompt window, you can just type the for %A in ("C:\Program Files") do @echo %~sA command, and if you type this into the “Run” dialog box, the result disappears before you can read it. May 28, 2018 at 19:21
  • 4
    Nicely done; as @Scott points out, you don't need the cmd /c when running from cmd; you do need it from PowerShell, but then you also need to '...'-enclose the tokens after /c: cmd /c 'for %f in ("C:\Program Files") do @echo %~sf'
    – mklement0
    Feb 14, 2019 at 15:49

I found very handy way to solve short pathname of current directory (or anything else) if you have Powershell installed.

Just open powershell in current dir

  • in cmd windows type powershell

  • if you have folder open in gui you can type cmd.exe or powershell.exe directly in address bar of folder.

Then give command

(New-Object -ComObject Scripting.FileSystemObject).GetFolder(".").ShortPath

Origin of information: [https://gallery.technet.microsoft.com/scriptcenter/Get-ShortName-90a49303]

  • 1
    Thanks! I had to use (New-Object -ComObject Scripting.FileSystemObject).GetFolder((Get-Location).Path).ShortPath though, because your version would always return "C:\Windows\System32"
    – Melvyn
    Dec 19, 2019 at 14:25

The "short name" is really the old DOS 8.3 naming convention, so all the directories will be the first 6 letters followed by ~1 assuming there is only one name that matches, for example:

C:\BCDEFG~1    - C:\BCDEFGHIJKL M Another Directory

here is the only exception

C:\ABCDEF~2    - C:\ABCDEFGHI Directory as well
  • 9
    Not true. Sometimes fewer characters are used, particularly if you are using asian characters, such as Korean.
    – Arafangion
    Sep 5, 2013 at 2:04
  • 1
    I suppose finding out which one is which in the "exceptional" case is the point of the question - especially as the "exception" regularly occurs in every Windows 64 bit installation, where you may need to know which one out of Program Files and Program Files (x86) is PROGRA~1 and which one is PROGRA~2. Paul's answer solves that issue. Feb 1, 2014 at 12:00
  • 2
    I have so many files that start with the same characters that after four of them (...~4) it started with what looks like hashing, e.g. ABxxxx~1 where x was hexadecimal -- which isn't very easy to read.
    – Andreas
    Nov 21, 2014 at 23:07
  • 2
    Are you suggesting that the user can figure out the short names logically by looking at the long names? That’s not true.  If I create ABCDEFGH-CAT, it gets short name ABCDEF~1. If I then create ABCDEFGH-DOG, it gets short name ABCDEF~2. If I then delete ABCDEFGH-CAT, ABCDEFGH-DOG, still has short name ABCDEF~2. There’s no way to tell just by looking at the long names. May 28, 2018 at 19:32
  • 1
    as said, the short name doesn't have to be the 6 first letters plus ~1. See the rule that Windows uses for generating short names. And you can also set the short name manually with fsutil, so the two names may have no relation whatsoever. Let alone hard or soft links
    – phuclv
    Jun 7, 2019 at 1:44

Similar to Ivan Schwartz's answer, you can replace "C:\Program Files" with %cd% to get current dir:

cmd /c for %A in ("%cd%") do @echo %~sA  
C:\Users\abcd>subst z: "c:\Program Files (x86)\Microsoft Office365 Tools\Microsoft Visual Studio 14.0"

Z:\: => C:\Program Files (x86)\Microsoft Office365 Tools\Microsoft Visual Studio 14.0"

This is the easiest way I have used when dealing with files with spaces and this is accessible from file explorer too has all the same access privileges.

  • This is the best approach.
    – munsingh
    Mar 16, 2022 at 7:46

for windows 10 users NONE of these solutions was working for on my windows 10 laptop since a key in the registry prohibited the creation of shortnames.. :

  • Alt+r, type regedit to open the registry editor
  • go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
  • look for the NtfsDisable8dot3NameCreation key : if the value is 0x00000001(1), then your system does not create any shortname for your folder/file
  • in this case double clic on the NtfsDisable8dot3NameCreation key,
  • type 0 in the data field

this is not retroactive :) I mean you need to recreate the folder/file you need to access from your old app.. maybe something clever is possible though I don't know yet.

it seems they introduced this key to speed up filesystem operations.

source microsoft : https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-2000-server/cc959352(v=technet.10)?redirectedfrom=MSDN

  • Did this does not work.
    – munsingh
    Mar 16, 2022 at 7:46
  • Note that disabling 8 dot 3 is not only a performance improvement, it's part of the remediation for an IIS vulnerability: serverfault.com/questions/670658/… (OK, you're probably (hopefully) not serving a public website from your laptop - this applies more on the server side)
    – unbob
    Nov 24, 2022 at 2:53

Alternatively, you could use this awesome little tool called PathCopyCopy

In a few clicks, you can get the long and short path of literally any folder from the contextual menu, e.g:

Right-click in the destination folder => Path Copy => Short Path.

Done. It will be copied to your clipboard.


@echo off
for %%i in (%*) do echo %%~si

Save it as shortpath.bat , and then drag files on it. Its result:

Press any key to continue . . .

Calling it with shortpath <file path> is also OK.


Just replace the spaces with


It's the way things are "translated", and spaces go into %20.

If you really need alot, simply pop open your browser and type something like

test ";($#< and find the word test, and see that the space is %20 and so on...
  • I don't think you're right. This does not produce a positive outcome: if exist C:\Program%20Files\ (echo exists) Sep 26, 2016 at 20:51
  • 3
    You're talking about something completely different. The main point is that directory and file names are truncated to 8 characters. The browser has nothing to do with that. Feb 21, 2017 at 10:26

I have installed node modules by running npm install on a boilerplate. While trying to delete those folders, windows does not allow us to delete them as path is too long to be able to handle.

After some of shallow research, I thought it would be right my own piece of code snippet to rename the folders from root to leaf so that it would throw any violation exception for this attempt as well.

It works for me. Following is the code for the C# project.

    public static int directoryCounterIndex = 0;
    public static void Main(string[] args)
        string dirPath = @"D:\Studies\MeanStack\a\nodem";

    private static void RenameDirectories(string dirPath)
        directoryCounterIndex += 1;
        var newPath = Path.GetDirectoryName(dirPath) + Path.DirectorySeparatorChar + directoryCounterIndex.ToString();
        Directory.Move(dirPath, newPath);
        var subDirectories = Directory.GetDirectories(newPath);
        foreach (var subDirectory in subDirectories)
  • 3
    Please read the question again carefully. Your answer does not answer the original question.
    – DavidPostill
    Nov 6, 2016 at 14:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .