GetFullPath

Versione 1.11.0.0 (19,7 KB) da Jan
Full path name for partial or relative path
7,3K download
Aggiornato 20 giu 2021

Visualizza la licenza

Nota dell'editore: 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.

Cita come

Jan (2026). GetFullPath (https://it.mathworks.com/matlabcentral/fileexchange/28249-getfullpath), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R2018b
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux
Categorie
Scopri di più su Filename Construction in Help Center e MATLAB Answers
Versione Pubblicato Note della release
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