Is there any way to convert a long filepath into a short (8.3 format) directly through the Java API (i.e. not using the command line)?
For example, it should convert C:\Program Files\Java
to C:\Progra~1\Java
.
Is there any way to convert a long filepath into a short (8.3 format) directly through the Java API (i.e. not using the command line)?
For example, it should convert C:\Program Files\Java
to C:\Progra~1\Java
.
You can use for example JNA as described in this SO answer
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);
}
// usage: java LongToShort "C:\Program Files (x86)\Java\jdk1.6.0_45"
public static void main(String[] args) {
System.out.println(GetShortPathName(args[0]));
}
}