버전 (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 CenterMATLAB Answers에서 File 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.