File Exchange Pick of the Week

Our best user submissions

Getting short path names

Jiro's pick this week is Short Path Name on Windows by Jerome Briot.

Thanks, Jerome! Your File Exchange entry helped me big time in my project. I was creating a program that managed a bunch of files, and some of the tasks required me to copy files from one network location to a new location. Sometimes, the new location would have a path name of 261 or more characters. In Windows API, 260 characters is the maximum number of characters allowed in a file path. I can overcome this issue if I map a drive to some path. For example,


However, I needed to make this a bit more portable so that my team members can use it on their machines. Then I remembered that back in the day, DOS used to abbreviate long path/file names (8.3 filename) to deal with its character limit. After Windows® 95, I've since slowly forgotten about the existence of 8.3 filename. But now, I have a real need for it.

I looked around the Web for the rules for converting a path name to a short path name. That's when I bumped into Jerome's entry. Rather than manually constructing the short file/path names, Jerome's functions uses Windows FileSystemObject (COM) to get the short names. This is obviously much more robust and the correct way.

thisFile = which(mfilename)
thisFile_short = fsoGetShortPath(thisFile)
thisFile =
C:\Users\jdoke\OneDrive for Business\MyStuff\Work\POTW\2015_06_26_ShortPathName\potw_shortname.m
thisFile_short =

Thanks again, Jerome. It worked perfectly!


Give this a try, let us know what you think here or leave a comment for Jerome.

Published with MATLAB® R2015a

  • print


댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.