📄 isabsolute.m
字号:
function [isabs, abspath] = isabsolute(tpath)
% isabsolute - returns true if the given path is absolute
%
% FORMAT: isabs = isabsolute(testpath)
%
% Input fields:
%
% testpath string to test for absolute path content
%
% Output fields:
%
% isabs true for absolute paths, false for relative
%
% See also EXIST
% Version: v0.5c
% Build: 6120415
% Date: Dec-04 2006, 3:15 PM CET
% Author: Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools
% argument check
if nargin < 1 || ...
~ischar(tpath) || ...
isempty(tpath)
error( ...
'BVQXtools:BadArgument', ...
'One non-empty 1xN char path argument is required.' ...
);
end
% make valid char argument
tpath = tpath(:)';
% get machine ostype
try
machine = ostype('machine');
machine = machine.machine;
catch
if ispc
machine = 'WIN';
else
machine = 'UNIX';
end
end
% default is false
isabs = false;
abspath = tpath;
% machine dependent code
switch (machine)
% for PCs/Windows hosts
case {'WIN'}
% for now, replace \'s with /'s
tpath = strrep(tpath, '\', '/');
% path can only be absolute for either of
% - X:\<...>
% - \\HOST\PATH_TO_UNC
if (length(tpath) > 2 && ...
tpath(1) > 64 && ...
tpath(1) < 123 && ...
(tpath(1) < 91 || tpath(1) > 96) && ...
strcmp(tpath(2:3), ':/') ...
) || ( ...
length(tpath) > 3 && ...
strcmp(tpath(1:2), '//'))
isabs = true;
elseif tpath(1) == '/'
pwdpath = cd; % see dbtype pwd
abspath = [pwdpath(1) ':' tpath];
else
abspath = strrep([pwd filesep tpath], '//', '/');
end
% for Linux/Unix'ish systems
case {'UNIX'}
% path can only be "absolute" for either of
% - /...
% - ~/...
if tpath(1) == '/' || ...
(length(tpath) > 1 && strcmp(tpath(1:2), '~/'))
isabs = true;
else
abspath = strrep([pwd filesep tpath], '//', '/');
end
% for Macintosh
case {'MAC'}
% path could be absolute for either of
% - /...
% - ~/...
if tpath(1) == '/' || ...
(length(tpath) > 1 && strcmp(tpath(1:2), '~/'))
isabs = true;
else
abspath = strrep([pwd filesep tpath], '//', '/');
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -