1 | function varargout = whichx(inputstr) |
---|
2 | %WHICHX file search within matlab search path using wildcards |
---|
3 | % For example, WHICHX *.m lists all the M-files in the matlab search paths. |
---|
4 | % |
---|
5 | % D = WHICHX('*.m') returns the results in an M-by-1 |
---|
6 | % structure with the fields: |
---|
7 | % name -- filename |
---|
8 | % date -- modification date |
---|
9 | % bytes -- number of bytes allocated to the file |
---|
10 | % isdir -- 1 if name is a directory and 0 if not% |
---|
11 | % path -- directory |
---|
12 | % |
---|
13 | % See also WHICH, DIR, MATLABPATH. |
---|
14 | |
---|
15 | % Autor: Elmar Tarajan [MCommander@gmx.de] |
---|
16 | % Version: 2.2 |
---|
17 | % Date: 2006/01/12 09:10:05 |
---|
18 | |
---|
19 | if nargin == 0 |
---|
20 | help('whichx') |
---|
21 | return |
---|
22 | end% if |
---|
23 | % |
---|
24 | if ispc |
---|
25 | tmp = eval(['{''' strrep(matlabpath,';',''',''') '''}']); |
---|
26 | elseif isunix |
---|
27 | tmp = eval(['{''' strrep(matlabpath,':',''',''') '''}']); |
---|
28 | else |
---|
29 | error('plattform doesn''t supported') |
---|
30 | end% if |
---|
31 | % |
---|
32 | if ~any(strcmpi(tmp,cd)) |
---|
33 | tmp = [tmp {cd}]; |
---|
34 | end% if |
---|
35 | % |
---|
36 | output = []; |
---|
37 | for i=tmp |
---|
38 | tmp = dir(fullfile(char(i),inputstr)); |
---|
39 | if ~isempty(tmp) |
---|
40 | for j=1:length(tmp) |
---|
41 | tmp(j).path = fullfile(char(i),tmp(j).name); |
---|
42 | end% for |
---|
43 | output = [output;tmp]; |
---|
44 | end% if |
---|
45 | end% for |
---|
46 | % |
---|
47 | if nargout==0 |
---|
48 | if ~isempty(output) |
---|
49 | if usejava('jvm') |
---|
50 | out = []; |
---|
51 | h = []; |
---|
52 | for i=1:length(output) |
---|
53 | % |
---|
54 | if ~mod(i,200) |
---|
55 | if ishandle(h) |
---|
56 | waitbar(i/length(output),h,sprintf('%.0f%%',(i*100)/length(output))) |
---|
57 | elseif isempty(h) |
---|
58 | h = waitbar(i/length(output),'','Name',sprintf('Please wait... %d files are founded.',length(output))); |
---|
59 | else |
---|
60 | return |
---|
61 | end% if |
---|
62 | drawnow |
---|
63 | end% if |
---|
64 | % |
---|
65 | [p f e] = fileparts(output(i).path); |
---|
66 | p = strrep([p filesep],[filesep filesep],filesep); |
---|
67 | e = strrep(['.' e],'..','.'); |
---|
68 | fl = strrep(output(i).path,'''',''''''); |
---|
69 | switch lower(e) |
---|
70 | case '.m' |
---|
71 | out = [out sprintf('<a href="matlab: %s">run</a> <a href="matlab:cd(''%s'')">cd</a> %s<a href="matlab:edit(''%s'')">%s%s</a>\n', f, p, p, fl, f, e)]; |
---|
72 | case {'.asv' '.cdr' '.rtw' '.tmf' '.tlc' '.c' '.h' '.ads' '.adb'} |
---|
73 | out = [out sprintf(' <a href="matlab:cd(''%s'')">cd</a> %s<a href="matlab:open(''%s'')">%s%s</a>\n', p, p, fl, f, e)]; |
---|
74 | case '.mat' |
---|
75 | out = [out sprintf(' <a href="matlab:cd(''%s'')">cd</a> %s<a href="matlab:load(''%s'');disp([''%s loaded''])">%s%s</a>\n', p, p, fl, fl, f, e)]; |
---|
76 | case '.fig' |
---|
77 | out = [out sprintf(' <a href="matlab:cd(''%s'')">cd</a> %s<a href="matlab:guide(''%s'')">%s%s</a>\n', p, p, fl, f, e)]; |
---|
78 | case '.p' |
---|
79 | out = [out sprintf('<a href="matlab: %s">run</a> <a href="matlab:cd(''%s'')">cd</a> %s\n', f, p, fl)]; |
---|
80 | case '.mdl' |
---|
81 | out = [out sprintf(' <a href="matlab:cd(''%s'')">cd</a> %s<a href="matlab:open(''%s'')">%s%s</a>\n', p, p, fl, f, e)]; |
---|
82 | otherwise |
---|
83 | if output(i).isdir |
---|
84 | out = [out sprintf(' <a href="matlab:cd(''%s'')">cd</a> %s\n', [p f], output(i).path)]; |
---|
85 | else |
---|
86 | out = [out sprintf(' <a href="matlab:cd(''%s'')">cd</a> %s<a href="matlab:try;winopen(''%s'');catch;disp(lasterr);end">%s%s</a>\n', p, p, fl, f, e)]; |
---|
87 | end% if |
---|
88 | end% switch |
---|
89 | end% for |
---|
90 | close(h) |
---|
91 | disp(char(out)); |
---|
92 | else |
---|
93 | disp(char(output.path)); |
---|
94 | end% if |
---|
95 | else |
---|
96 | disp(['''' inputstr '''' ' not found.']) |
---|
97 | end% if |
---|
98 | else |
---|
99 | varargout{1} = output; |
---|
100 | end% if |
---|