Short and long path name on Windows (MEX)

版本 1.4.0.0 (4.4 KB) 作者: Jerome Briot
Conversion between short and long form of path name on Windows
277.0 次下载
更新时间 2015/1/5

查看许可证

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);
dos(cmd)

The short form paths are:

notepadShortPath =

C:\PROGRA~2\NOTEPA~1\NOTEPA~1.EXE

fileShortPath =

UNFICH~1.TXT

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

引用格式

Jerome Briot (2025). Short and long path name on Windows (MEX) (https://www.mathworks.com/matlabcentral/fileexchange/48949-short-and-long-path-name-on-windows-mex), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2014b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Search Path 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.4.0.0

Title updated

1.3.0.0

Typo in the example

1.2.0.0

Better example

1.1.0.0

Minor update

1.0.0.0