2

On Windows 10, I have created the following folder:

C:\BigLongFolderName

If I run the following test.bat from Windows Explorer with "Run as Administrator" on the right-click context menu from within the above folder, I get a shortened 8.3 folder name.

test.bat

echo "%~dp0"
echo %~dp0

Output:

C:\windows\system32>echo "C:\BIGLON~1\"
"C:\BIGLON~1\"

C:\windows\system32>echo C:\BIGLON~1\
C:\BIGLON~1\

How do I get the long folder name in Windows 10 when using "Run as Administrator"?

The output I want to see is C:\BigLongFolderName\

I do literally have a folder called C:\BigLongFolderName on my machine.

If I run the same test.bat by double-clicking on it (instead of "Run as Administrator") then I am echoed the full C:\BigLongFolderName path as I would expect. Why does "Run as Administrator" not give me the long path?

I moved this question from Stackoverflow as "its not a programming question".

The following post suggests that I should be getting long name format by default and indeed my 2 of my collegues do:

https://stackoverflow.com/questions/15567809/batch-extract-path-and-filename-from-a-variable

Please note that I not want to convert 8.3 names into long names. I want the long names to be returned sames as other people are getting.

17
  • You do understand, don't you?, that you have a folder named C:\BIGLON~1\. The folder has two names: a SFN (short filename) and an LFN (long filename). Those are both valid names for the same folder.
    – TOOGAM
    Jan 11, 2018 at 4:39
  • That's strange. For me it's working correctly. Some few notes... You say you run this from the Windows Explorer. If you do, and you don't have pause in the test.bat, you'll see a black screen disappear very quickly. Not quickly enough for you to copy and paste your result. I used pause and got C:\BigLongFolderName twice. I also ran this in cmd.exe and got the same result. HOWEVER, if you run this from command.com you will get the short names (command.com is the old 16-bit command line for DOS programs). (note the difference in cmd.exe and command.com)
    – Rik
    Jan 11, 2018 at 9:58
  • Also... if you run it directly from C:\BIGLON~1 you'll always get the short 8.3 folder name.
    – Rik
    Jan 11, 2018 at 10:00
  • @TOOGAM Yes, I understand that short and long names are the same folder. Imagine if you subst' a logical drive (such as J:) many times a day to different folders all endng in version numbers blahblahblah1.0, blahblahblah1.1 etc and you want to double-check which folder you are currently subst' to. I usually type in 'subst' and it tells me. You can't tell with 8.3 format.
    – SparkyNZ
    Jan 11, 2018 at 17:50
  • 1
    You may be able to fix this (or get a helpful error message) by disabling 8.3 filenames, and then renaming the folder to ensure it gets a new directory entry (without the 8.3 duplicate pointer). You probably should backup your registry before trying this.
    – jpaugh
    Jan 11, 2018 at 20:11

1 Answer 1

2

Disable 8.3 file names. You'll need to rename existing folders to clean up the existing 8.3 filename entries. There may be a tool to clean these up automatically, but I'm not sure. (fsutil file setshortname C:\BigFolderName "" may work.)

You must log in to answer this question.

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