-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathenhanced_rdir.m
executable file
·65 lines (46 loc) · 1.73 KB
/
enhanced_rdir.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
%% RDIR Enhanced - Examples of use
%
% This script demonstrates how to use the different abilities of the
% enhanced |rdir| function.
%
% Examples are based on |matlabroot| directory content. Results may vary
% depending on your version of Matlab.
%
%% Standard use
rdir([matlabroot, '\*.txt'])
%% Using double wildcard **
% List |".m"| files whose name contains |"tmpl"| in all subdirectories of
% |matlabroot|
rdir([matlabroot, '\**\*tmpl*.m'])
%% RDIR output
d = rdir([matlabroot, '\**\*tmpl*.m'])
%%
disp(d(1))
%% Using 3rd argument to shorten output names
% Remove |"C:\Program Files\"| in returned names
rdir([matlabroot, '\*.txt'], '', 'C:\Program Files\')
%%
% Remove |matlabroot| in returned names
rdir([matlabroot, '\*.txt'], '', true)
%%
% Optional 2nd |rdir| output indicates common path removed from each output
% name
[d, p] = rdir([matlabroot, '\*.txt'], '', true);
fprintf('Common path : \n%s\n\n', p)
disp( d(1) )
%% Using a filter with "regexp"
% List |".mat"| files, then select those whose name match regular expression
% |'data\d'| (ie |"data"| followed by a numeric digit)
rdir([matlabroot '\toolbox\**\*.mat'], 'regexp(name, ''data\d'')', true)
%% Using a function handle as filter
fun = @(d) ~isempty(regexp(d.name, 'data\d')) && (d.bytes < 10*1024)
rdir([matlabroot '\toolbox\**\*.mat'], fun, true)
%% Specific display - No item matching filter
% When some items match input path, but none match filter, a specific
% message is displayed.
rdir(matlabroot, 'strcmp(name, ''unknowtoolbox'')', 1)
%% Specific display - Wrong filter
% A warning is displayed after the non-filtered result list if entered
% filter is wrong.
rdir(matlabroot, 'wrong filter', 1)
% EOF