バージョン (19.7 KB) 作成者: Jan
Full path name for partial or relative path
ダウンロード: 7.1K
更新 2021/6/20


編集メモ: This file was selected as MATLAB Central Pick of the Week

GetFullPath - Get absolute path of a file or folder name
This function converts a partial or relative name to an absolute full path name. The fast Mex works on Windows only, but the M-file runs on Windows, MacOS and Unix.
FullName = GetFullPath(Name, Style)
Name: Char, string or cell string, file or folder name with relative or absolute path.
UNC paths accepted. Path need not exist.
Style: Special styles for long file names under Windows:
'auto': Add '//?/' for long names (> 255 characters). (default)
'lean': No '//?/'.
'fat': '//?/' added for short names also.
FullName: Char or cell string, file or folder name with absolute path.
cd(tempdir); % Assuming C:\Temp here
GetFullPath('File.Ext') % ==> 'C:\Temp\File.Ext'
GetFullPath('..\File.Ext') % ==> 'C:\File.Ext'
GetFullPath('.\File.Ext') % ==> 'C:\Temp\File.Ext'
GetFullPath('*.txt') % ==> 'C:\Temp\*.txt'
GetFullPath('D:\Folder1\..\Folder2') % ==> 'D:\Folder2'
GetFullPath('\') % ==> 'C:\', current drive!
GetFullPath('Folder\') % ==> 'C:\Temp\Folder\'
% ==> '\\Server\Folder\File.ext'
WHICH: only for existing files, ~24 times slower.
System.IO.FileInfo: .NET (thanks Urs), more features, ~50 times slower. "/.." and "/." are fixed by getCanonicalPath (~6 times slower),
but no completing of partial/relative path.
Tested: Matlab 2009a, 2011b, 2018b, WinXP/32, Win7/64, Win10/64
Installation: See ReadMe.txt
Suggestions and question by email or in the comment section are very welcome.


Jan (2024). GetFullPath (, MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2018b
Windows macOS Linux
Help Center および MATLAB AnswersFile Name Construction についてさらに検索

Community Treasure Hunt

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

Start Hunting!
バージョン 公開済み リリース ノート

Typo fixed in InstallMex. No changes in actual function.

Unit test function added

Accept strings as input.

Bugfix in M-File for UNC path.

Unit test fixed: Consider buggy FULLFILE ov Matlab >= 2015b: FULLFILE('C:\', '\') replies 'C:\\' !
Improved handling of inputs with '//?/' prefix. 2nd input to control prefix in the output. New InstallMex function.

C-Mex tested under Win7/64. Improved UNC path support in the M-file. Bugfix for M-file under Linux (thanks Daniel).

Minor bug: '***' in the ErrorID caused bad messages in case of errors.

Bugfix in M-version: Treat empty matrix as empty string.

Accept cell strings as inputs.

M-Version replied bad path for input with leading separator. GetFullPath('\') is the current drive on Windows.

Doc updated, function not touched.