-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglob.m
More file actions
43 lines (37 loc) · 1.05 KB
/
Copy pathglob.m
File metadata and controls
43 lines (37 loc) · 1.05 KB
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
function X = glob(str, dirname, convert_to_cell)
% functions similarly to ls (using a wildcard*) and glob in python
% str can be any string, either a full path to the desired file(s) or the
% string corresponding to the name of file (without full path). If no path
% is provided in str, can be given in dirname or is assumed to be the
% current directory
if nargin==1;
d = dir(str);
[p] = fileparts(str);
if isempty(p); dirname = [pwd '/'];
else dirname = p;
end
else
if isempty(strmatch(dirname(end),'/'));%==1;
dirname = [dirname '/'];
end
d = dir([dirname str]);
if nargin < 3; convert_to_cell = 0; end
end
if ~isempty(d);
[X{1:length(d)}] = deal(d.name);
X = X';
if length(X)==1;
X = [dirname X{1}];
if convert_to_cell==1;
Out{1} = X; clear X;
X = Out; clear Out;
end
else
for irow = 1:length(X)
X{irow} = [dirname X{irow}];
end
end
else
warning('No desired files in directory')
X = {};
end