vb_realpath returns absolute path. [USAGE] [abs_path, err] = vb_realpath(input_path); [IN] input_path : relative path or absolute path or relative file name or absolute file name [OUT] abs_path : absolute path err : = 0 % error not occured. Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [abs_path, err] = vb_realpath(input_path) 0002 % vb_realpath returns absolute path. 0003 % [USAGE] 0004 % [abs_path, err] = vb_realpath(input_path); 0005 % [IN] 0006 % input_path : relative path or absolute path or 0007 % relative file name or absolute file name 0008 % [OUT] 0009 % abs_path : absolute path 0010 % err : = 0 % error not occured. 0011 % 0012 % Copyright (C) 2011, ATR All Rights Reserved. 0013 % License : New BSD License(see VBMEG_LICENSE.txt) 0014 0015 % 0016 % --- Previous check 0017 % 0018 if ~exist('input_path', 'var'), input_path = ''; end 0019 0020 % 0021 % --- Main Procedure 0022 % 0023 err = 0; 0024 abs_path = []; 0025 f_path = []; 0026 is_file = false; 0027 0028 if exist(input_path, 'file') == 2 0029 [f_path, f_name, f_ext] = vb_get_file_parts(input_path); 0030 is_file = true; 0031 elseif exist(input_path, 'dir') == 7 0032 f_path = input_path; 0033 else 0034 err = 1; % directory not found. 0035 return; 0036 end 0037 0038 % get absolute path 0039 pushd = pwd; 0040 if ~isempty(f_path) 0041 cd(f_path); 0042 end 0043 abs_path = pwd; 0044 cd(pushd); 0045 0046 % make file 0047 if is_file 0048 abs_path = [abs_path, filesep, f_name, f_ext]; 0049 end