File Exchange

image thumbnail

Short and long path name on Windows (MEX)

version 1.4 (4.38 KB) by

Conversion between short and long form of path name on Windows

1 Download


View License

getShortPath converts a path name (or a file name) to its short form (MSDOS 8.3). getLongPath do the opposite.
getShortPath is useful to deal with poorly formed path (eg path name with special characters or spaces) when using the dos builtin function. No need to add double quotes to the path name.
For example, to open a file nammed "un fichier mal nommé.txt" with Notepad++. The following command fails:
        dos('C:\Program Files (x86)\Notepad++\notepad++.exe un fichier mal nommé.txt')

You need to add double quotes:

        dos('"C:\Program Files (x86)\Notepad++\notepad++.exe" "un fichier mal nommé.txt"')

Or use getShortPath:

        notepadShortPath = getShortPath('C:\Program Files (x86)\Notepad++\notepad++.exe');
        fileShortPath = getShortPath('un fichier mal nommé.txt');
        cmd = sprintf('%s %s', notepadShortPath, fileShortPath);

The short form paths are:

        notepadShortPath =


        fileShortPath =


Codes are based on the Win32 API and therefore are only supported on Windows systems. Compile MEX files first.

Comments and Ratings (0)



Title updated


Typo in the example


Better example


Minor update

MATLAB Release
MATLAB 8.4 (R2014b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video