-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsp_exist.m
44 lines (39 loc) · 979 Bytes
/
sp_exist.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function A = sp_exist(name, kind)
% function A = sp_exist(name, kind)
%
% A wrapper for exist, which behaves differently for:
% kind=='file' || kind=='dir' -> returns a boolean
% but behaves the same as exist for all other values of kind
%
% INPUTS:
% name: [string]
% kind: [string]
%
% OUTPUTS:
% A: [bool] for kind=='file' || kind=='dir', OR the return value from exist
%
% Sagi Perel, 09/2012
if(nargin ~= 2)
error('sp_exist: wrong number of input arguments provided');
end
if(~ischar(name))
error('sp_exist: name must be a string');
end
if(~ischar(kind))
error('sp_exist: kind must be a string');
end
A = exist(name, kind);
switch(kind)
case 'file'
if(A==2)
A = true;
else
A = false;
end
case 'dir'
if(A==7)
A = true;
else
A = false;
end
end