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 (sorry), but the M-file runs on Windows, MacOS and Unix.
FullName = GetFullPath(Name)
INPUT:
Name: String or cell string, file or folder name with relative or absolute path.
OUTPUT:
FullName: String or cell string, file or folder name with absolute path.
The created path need not exist.
EXAMPLES:
cd(tempdir); % Assuming C:\Temp here
GetFullPath('File.Ext') % ==> 'C:\Temp\File.Ext'
GetFullPath('..\File.Ext') % ==> 'C:\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:\'
GetFullPath('\') % ==> 'C:\', current drive!
GetFullPath('Folder\') % ==> 'C:\Temp\Folder\'
GetFullPath('\\Server\Folder\Sub\..\File.ext')
% ==> '\\Server\Folder\File.ext'
See also (timings converted with GetFullPath):
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 6.5, 2008a, 2009a, 2001b, WinXP/32, Win7/64
Compiler: LCC 2.4/3.8, OpenWatcom 1.8, BCC 5.5, MSVC 2008/2010
Precompiled Mex: http://www.n-simon.de
Suggestions and question by email or in the comment section are very welcome - especially a test under Linux and MacOS. |