1

As a java software programmer, I'm used to create batch scripts for my software. In these scripts, I get the short name of the folders I work with, in order to make sure the software will work with command prompt (cmd). But then, one of my users on Windows 10 told me the software did not work on his computer. After some researches, I discovered that the algorithm that used to give me the folder short name did not work on his computer

I tried the same test code on various computers with different windows versions, and only on his computer I just could not get the expected short names.

Test code extracting the short name (sorry for the french text: it is for french users):

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
@ECHO -------------------------------------
@ECHO Version de Windows :
ver
@ECHO -------------------------------------
REM Test de nom court
SET ROOT_DIR=%~dp0
SET TMP_DIR=""
REM for "usebackq delims=" /d %%I in ("%ROOT_DIR%") do (
for /d %%I in ("%ROOT_DIR%") do (
  if %TMP_DIR% == "" (
    SET TMP_DIR=%%~sI
  )
)
@ECHO test nom court du dossier courant: '%TMP_DIR%'
PAUSE

For example, with this folder (with deliberate long name) and given batch code:

D:\aa aaaaaa aa\vcxvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\ccccccccccggggggggggggttttttttttttttttrrrrrrrrr           dsdqkdhqk  ;
  • On a windows 7 computer, I get this result:
-------------------------------------
Version de Windows :

Microsoft Windows [version 6.1.7601]
-------------------------------------
test nom court du dossier courant: 'D:\AAAAAA~1\VCXVVV~1\CCCCCC~1\'
Appuyez sur une touche pour continuer...
  • On my user's windows 10 computer, I get this result:
-------------------------------------
Version de Windows :

Microsoft Windows [version 10.0.17134.1040]
-------------------------------------
test nom court du dossier courant: 'D:\aa aaaaaa aa\vcxvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\ccccccccccggggggggggggttttttttttttttttrrrrrrrrr           dsdqkdhqk  ;'
Appuyez sur une touche pour continuer...

Due to this kind of answer, my batch scripts won't work because the command prompt will raise errors for too long lines.

Does anyone have any idea about how to get the expected short names on windows 10?

I don't know if it will help (I'm not a windows expert), but I did some research with regedit on his computer, and I found these:

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\FileSystem\NtfsAllowExtendedCharacter8dot3Rename = 0

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\FileSystem\NtfsDisable8dot3NameCreation = 2

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet\Control\FileSystem\NtfsAllowExtendedCharacter8dot3Rename = 0

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet\Control\FileSystem\NtfsDisable8dot3NameCreation = 2

Thank you by advance for any solution to that problem.

Regards,

11
  • dir /x list shortnames.. so if you execute something like this you'll get the idea @for /f "tokens=4" %%i in ('dir /ad /x ^| find "~"') do @echo %%~i Commented Nov 6, 2019 at 12:02
  • To enable the creation of 8.3 filenames, you could try either, "%__AppDir__%fsutil.exe" Behavior Set Disable8dot3 0 or "%__AppDir__%reg.exe" Add HKLM\SYSTEM\CurrentControlSet\Control\FileSystem /V NtfsDisable8dot3NameCreation /T REG_DWORD /D 0 /F. In both cases you should run the commands 'As administrator'. I will also add that you should really try to explain what the issue is with using the long filenames. There are potential workarounds for some issues and those would be better than having to get all end users machines Admin configured. Commented Nov 6, 2019 at 12:07
  • dir /x won't help (I already know this command), because it lists the files in your folder, but doesn't give you the short path of your folder. Commented Nov 6, 2019 at 12:57
  • 1
    A value of 0 enables applications that cannot process long file names and computers that use different code pages to find the files. A value 2 sets the 8.3 naming convention creation on a per volume basis. Perhaps therefore it's the volume or even it's file system that's different for the other PC user. At this stage you should post your actual code with the long filenames, together with the actual name of the software being used and sufficient information for us to replicate your issue. We could then try to fix the code without having to resort to short file naming. Commented Nov 6, 2019 at 13:25
  • 1
    The only limitation of this is that it doesn't work in previously created folders : these folders were not created with short names, so there is no possibility to get their short name... Commented Nov 7, 2019 at 9:39

1 Answer 1

1

@Compo had the right answer: My user has windows 10 pro with a SSD. On windows 10 (at least pro), the default behaviour concerning SSD seems to be "do not allow short file names".

So, I put the "NtfsDisable8dot3NameCreation" registry value to 0 using this command with PowerShell run as administrator:

Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\FileSystem\" -Name NtfsDisable8dot3NameCreation -Value 0

After rebooting the computer and installing my software to a new folder, it did work.

The only limitation of this is that it doesn't work in previously created folders: these folders were not created with short names, so there is no possibility to get their short name...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.