-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsortls.m
84 lines (76 loc) · 1.85 KB
/
sortls.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
% SORTLS
%
% Function SORTLS sorts list of direcotory content into the directories
% and files.
%
% [files,dirs,unknown,hiddenfiles] = sortls(dirpath,hidesymbol)
%
% files:cell - is output list of files
% dirs:cell - is output list of directories
% unknown:cell - is output list of unsorted items
% hiddenfiles:cell- is output list of hidden files
% dirpath:char - is input path of directory to be listed, current
% direcotry is used, when input DIRPATH is omitted
% hidensymbol - is symbol of hidden files, e.g. ".", "~", ect.
%
% DEPS:EXTERNAL: - LS2CELL
%
%
% est.2014.03.06.
%
function [files,dirs,unknown,hiddenfiles] = sortls(dirpath,hidesymbol)
% Default Value of Input
%
if(nargin == 0)
dirpath = pwd;
end
%
% To recognize Hidden Files
%
if(nargin == 2)
chk_hiden = 1;
else
chk_hiden = 0;
end
% Initial Values of Outputs
%
files = [];
dirs = [];
unknown = [];
hiddenfiles = [];
% Load LIST of directory-content and CHK_DIR
%
[list,chk_dir] = ls2cell(dirpath);
% Counters
%
cntF = 0;
cntD = 0;
cntU = 0;
cntH = 0;
for k = 1 : length(list)
if (chk_dir(k) == 1)
cntD = cntD + 1;
dirs{cntD,1} = list{k};
elseif(chk_dir(k) == 0)&(chk_hiden == 0)
cntF = cntF + 1;
files{cntF,1} = list{k};
elseif(chk_dir(k) == 0)&(chk_hiden == 1)
if(length(list{k}) > length(hidesymbol))
if(list{k}(1:length(hidesymbol)) == hidesymbol)
cntH = cntH + 1;
hiddenfiles{cntH,1} = list{k};
else
cntF = cntF + 1;
files{cntF,1} = list{k};
end % if
else
cntF = cntF + 1;
files{cntF,1} = list{k};
end % if
else
cntU = cntU + 1;
unknown{cntU,1} = list{k};
end % if
end % for k
end % function