source: MML/trunk/applications/common/whichx.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 3.6 KB
Line 
1function 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
19if nargin == 0
20   help('whichx')
21   return
22end% if
23%
24if ispc
25   tmp = eval(['{''' strrep(matlabpath,';',''',''') '''}']);
26elseif isunix
27   tmp = eval(['{''' strrep(matlabpath,':',''',''') '''}']);
28else
29   error('plattform doesn''t supported')
30end% if
31%
32if ~any(strcmpi(tmp,cd))
33   tmp = [tmp {cd}];
34end% if
35%
36output = [];
37for 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
45end% for
46%
47if 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
98else
99   varargout{1} = output;
100end% if
Note: See TracBrowser for help on using the repository browser.