GetFullPath

Version 1.11.0.0 (19.7 KB) by Jan
Full path name for partial or relative path
7.2K Downloads
Updated 20 Jun 2021

View License

Editor's Note: 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)
INPUT:
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.
OUTPUT:
FullName: Char or cell string, file or folder name with absolute path.
EXAMPLES:
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\'
GetFullPath('\\Server\Folder\Sub\..\File.ext')
% ==> '\\Server\Folder\File.ext'
Alternatives:
WHICH: only for existing files, ~24 times slower.
System.IO.FileInfo: .NET (thanks Urs), more features, ~50 times slower.
java.io.File: "/.." 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.

Cite As

Jan (2024). GetFullPath (https://www.mathworks.com/matlabcentral/fileexchange/28249-getfullpath), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2018b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Filename Construction in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.11.0.0

Typo fixed in InstallMex. No changes in actual function.

1.10.0.0

Unit test function added

1.9.0.0

Accept strings as input.

1.8.0.0

Bugfix in M-File for UNC path.

1.7.0.0

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.

1.6.0.0

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

1.5.0.0

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

1.4.0.0

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

1.3.0.0

Accept cell strings as inputs.

1.2.0.0

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

1.1.0.0

Doc updated, function not touched.

1.0.0.0