-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgetDir.m
More file actions
26 lines (23 loc) · 759 Bytes
/
getDir.m
File metadata and controls
26 lines (23 loc) · 759 Bytes
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
function [folders,fullpath]=getDir(path,type,varargin)
%optional third argument specifying string requirement to filter
%file/folder names
folders=dir(path);
dirs=[folders.isdir];
folders={folders.name};
if ~isempty(folders)
idx=cellfun(@strncmp,folders,repmat({'.'},1,length(folders)),repmat({1},1,length(folders)));
if strcmpi(type,'folder')
folders(idx|~dirs)=[];
elseif strcmpi(type,'file')
folders(idx|dirs)=[];
else
error('Unknown content type.')
end
if ~isempty(varargin)
cond = cellfun(@strfind,folders,repmat(varargin(1),1,length(folders)),'UniformOutput',0);
cond = ~cellfun(@isempty,cond);
folders(~cond)=[];
end
fullpath = cellfun(@(x,p) fullfile(p,x),folders,repmat({path},1,length(folders)),'UniformOutput',0);
end
end