Here are some ways to find the short name of a directory.
Windows CMD
dir /X "C:\Program Files (x86)*"
as VB script
' usage: cscript shortname.vbs [directory]
'
' example: cscript shortname.vbs "C:\Program Files (x86)\Java\jdk1.6.0_45"
on error resume next
Set fso=CreateObject("Scripting.FileSystemObject")
Set objFolder = fso.GetFolder(WScript.Arguments(0))
Set objSubFolders = objFolder.SubFolders
For Each sf In objSubFolders
WScript.Echo sf.ShortPath
Next
Set objFiles = ObjFolder.Files
For Each file In objFiles
WScript.Echo file.ShortPath
Next
Java using JNA
import com.sun.jna.Native;
import com.sun.jna.platform.win32.Kernel32;
public class LongToShort {
public static String GetShortPathName(String path) {
char[] result = new char[256];
Kernel32.INSTANCE.GetShortPathName(path, result, result.length);
return Native.toString(result);
}
// java LongToShort "C:\Program Files (x86)\Java\jdk1.6.0_45"
public static void main(String[] args) {
System.out.println(GetShortPathName(args[0]));
}
}
edit
Example how to change the JAVA_HOME environment variable.
Assuming your JDK is installed in C:\Program Files (x86)\Java\jdk1.6.0_45
.
The short name of C:\Program Files (x86)
might be PROGRA~1
.
Change your JAVA_HOME:
from set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_45
to set JAVA_HOME=C:\PROGRA~1\Java\jdk1.6.0_45