0

I am using windows and need to access a directory and file name that contains spaces. Right clicking the file and choosing properties use to show the non space short name, but it seems windows 7 no longer does this. I'm also at work so I can't install dosbox.

I'm trying to create a file:// url for the file. The path is:

myserver\SHARED ITEMS\My File.txt

How do I get the name that looks something like

file://myserver/shared~1/My~1.txt
dbenham
  • 127,446
  • 28
  • 251
  • 390
Superdooperhero
  • 7,584
  • 19
  • 83
  • 138

1 Answers1

2

Read about spaces in URL and percent encoding. However, % has special meaning in Windows CLI and cmd batch files...

Read 8.3 file name creation on NTFS partitions. You could see 8.3 filenames using dir /X supposing those are enabled for a particular volume. However, it will work on local drives only: under administrator command prompt, one can query NTFS filesystem using the fsutil.exe utility:

C:\Windows\system32>fsutil.exe behavior query Disable8dot3 c:
The volume state is: 0 (8dot3 name creation is enabled).
The registry state is: 2 (Per volume setting - the default).

Based on the above two settings, 8dot3 name creation is enabled on c:

C:\Windows\system32>fsutil.exe behavior query Disable8dot3 d:
The volume state is: 1 (8dot3 name creation is disabled).
The registry state is: 2 (Per volume setting - the default).

Based on the above two settings, 8dot3 name creation is disabled on d:

C:\Windows\system32>net use y: \\SERVER-PC\VB_scripts_help
The command completed successfully.

C:\Windows\system32>fsutil.exe behavior query Disable8dot3 y:
Error:  Access is denied.

Here the FSUTIL behavior query against a mapped drive raises the Access is denied error because it can't query remote filesystem (which may not be NTFS nota bene)...

But even on a local drive with 8dot3 name creation enabled, next example shows that 8.3 names are not solvable unambiguously:

==>D:\bat\StackOverflow\30453582.bat

 Directory of C:\testC\New Folder 12

26.05.2015  15:34                 0 NEWTEX~1     New Text File 1
26.05.2015  15:34                 0 NEWTEX~2     New Text File 2
               2 File(s)              0 bytes

 Directory of C:\testC\New Folder 21

26.05.2015  15:34                 0 NEWTEX~2     New Text File 1
26.05.2015  15:34                 0 NEWTEX~1     New Text File 2
               2 File(s)              0 bytes

Previous output comes from next batch script:

@ECHO OFF >NUL
MD C:\testC 2>nul
pushd C:\testC
MD "New Folder 12" 2>nul
type NUL>"New Folder 12\New Text File 1"
type NUL>"New Folder 12\New Text File 2"
dir /X   "New Folder 12" | findstr /I /V "Volume"| findstr /I /V "<DIR> free"
MD "New Folder 21" 2>nul
type NUL>"New Folder 21\New Text File 2"
type NUL>"New Folder 21\New Text File 1"
dir /X   "New Folder 21" | findstr /I /V "Volume"| findstr /I /V "<DIR> free"
popd
Community
  • 1
  • 1
JosefZ
  • 28,460
  • 5
  • 44
  • 83