-
Notifications
You must be signed in to change notification settings - Fork 16
/
perceive_ffind.m
96 lines (83 loc) · 2.27 KB
/
perceive_ffind.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function [files,folder,fullfname] = perceive_ffind(string,cell,rec)
if ~exist('cell','var')
cell = 1;
end
if ~exist('rec','var')
rec = 0;
end
if ~rec
x = ls(string);
if size(x,1)>1
files = cellstr(ls(string));
else
% On unix, the output of 'ls' is a rich text, see the help for LS:
% >> On UNIX, LS returns a character row vector of filenames
% >> separated by tab and space characters.
% On top of that, the text terminates with a newline.
% Therefore, we can't split only on spaces, but also on tabs and newlines:
files = strsplit(x);
% On unix, splitting on newlines can result in the last entry being empty,
% so we remove empty entries:
if ~isempty(files)
nonempty=repmat(true,1,length(files));
for i=1:length(files)
if isempty(files{i})
nonempty(i)=false;
end
end
files=files(nonempty);
end
end
for a =1:length(files)
ff = fileparts(string);
if ~isempty(ff)
folder{a} = ff;
else
folder{a} = cd;
end
end
else
rdirs=find_folders;
outfiles=ffind(string,1,0);
outfolders = {};
folders = {};
for a = 1:length(outfiles)
outfolders{a} = cd;
end
for a=1:length(rdirs)
files=ffind([rdirs{a} filesep string],1,0);
if ~isempty(files)
for b = 1:length(files)
folders{b,1} = [rdirs{a}];
end
outfiles = [outfiles;files];
outfolders = [outfolders;folders];
end
end
files = outfiles;
folder = outfolders;
end
ris = logical(sum([ismember(files,'.') ,ismember(files,'..')],2));
files(ris)=[];
folder(ris)=[];
[files,x]=unique(files);
folder = folder(x);
% keyboard
if ~isempty(files)
if ~cell && length(files) == 1
files = files{1};
fullfname = [folder{1} filesep files];
elseif iscell(files) && isempty(files{1})
files = [];
folder = [];
fullfname = [];
elseif iscell(files)
for a=1:length(files)
fullfname{a,1} = [folder{a} filesep files{a}];
end
end
else
folder = [];
fullfnames = [];
end
% keyboard