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,
dir /xlist 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"%__AppDir__%fsutil.exe" Behavior Set Disable8dot3 0or"%__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.0enables applications that cannot process long file names and computers that use different code pages to find the files. A value2sets 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.