-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfilesortstruct.m
37 lines (28 loc) · 920 Bytes
/
filesortstruct.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
function [filesort, numfiles] = filesortstruct( filename, varargin )
%filesortstruct.m Creates a directory list with fileparts
% Creates a directory list with extra fields for fileparts
dirflag = false;
while ~isempty(varargin)
switch upper(varargin{1})
case 'DIR'
dirflag = true;
varargin(1) = [];
otherwise
error(['Unexpected option: ' varargin{1}])
end
end
filesort = dir(filename);
if dirflag == true || strcmpi(filename,'DIR')
isdirlog = ~[filesort.isdir];
filesort(isdirlog) = [];
isdot = logical(strcmp('.',{filesort.name}) + strcmp('..',{filesort.name}));
filesort(isdot) = [];
numfiles = numel(filesort);
else
numfiles = numel(filesort);
for L = 1:numfiles
[filesort(L).pathstr, filesort(L).firstname, filesort(L).ext] = ...
fileparts([filesort(L).name]);
end
end
end