NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/util/cdd.m

Revision 495 (checked in by cbc, 11 years ago)

Initial import of Stark code.

Line 
1 function WorkingDirectory = cdd(dirname)
2 % CDD    Change directories using the wildcard *
3 %   Change directories using * as a wildcard in the search
4 %   directory string name.  The wildcard (*) may be placed either
5 %   at the beginning or end of the search string.  Only a
6 %   single wildcard (*) is allowed.
7 %
8 %   CDD .. moves to the parent directory of the current one.
9 %   CDD, by itself, displays the current working directory.
10 %
11 %   WD = CDD returns the current directory in the string WD.
12 %
13 %   The functional form of CDD, such as CDD('DirectoryWildcard'),
14 %   may be used when the target directory specification is
15 %   stored in the string DirectoryWildcard.
16 %
17 %   For example, to change to directory TargetDirectory,
18 %
19 %       CDD Tar*  or  CDD *dire  or  CDD *tory
20 %
21 %   CDD is case sensitive, but insensitive to the occurrence of
22 %   spaces in the name of the target directory so that
23 %
24 %       CDD Pro*  or  CDD *File
25 %
26 %   changes to the directory "Program Files".
27 %
28 %   Created by A. Prasad
29 %   Updated 8 May 1999
30 %
31 %   See also CD, PWD
32
33 if nargin < 1
34    if nargout < 1
35       disp(' ');
36       disp(pwd);
37       disp(' ');
38    elseif nargout == 1
39       WorkingDirectory = pwd;
40     else
41       disp('???  Error using ==> cdd');
42       disp('Incorrect number of arguments.');
43       disp('  ');
44    end
45    break
46 end     
47
48 if strcmp(dirname,'..') == 1,
49      cd('..');
50      break
51 elseif strcmp(dirname,'.') == 1,
52      break
53 end
54
55 LengthDirName = length(dirname);
56
57 % Find asterisk character and quit if more than single wildcard
58 asterisk = find(dirname=='*');
59 if length(asterisk) > 1,
60      disp('???  Error using ==> cdd');
61      disp('Too many wildcards.');
62      disp('  ');
63      break
64 elseif isempty(asterisk) == 1
65      disp('???  Error using ==> cdd');
66      disp('Invalid wildcard.');
67      disp('  ');
68      break
69 else
70      if asterisk == length(dirname),
71           SrchDirName = dirname(1:(LengthDirName-1));
72           CurrentDir = dir;
73           FindTargetDir = 0;
74           for i=1:length(CurrentDir),
75                dirflag = {CurrentDir.isdir};
76                if dirflag{i} == 1,
77                     SubDirList = {CurrentDir.name};
78                     FindTargetDir = strncmp(SubDirList{i},SrchDirName,(LengthDirName-1));
79                     if FindTargetDir == 1
80                          TargetDirName = SubDirList{i};
81                          cd(TargetDirName);
82                          CurrentDirectory = pwd
83                          break
84                     end
85                end
86           end
87           if FindTargetDir == 0,
88                disp('??? Error using ==> cdd');
89                disp('Target directory not found.');
90                disp('  ');
91           end
92      elseif asterisk == 1,
93           SrchDirName = dirname(2:LengthDirName);
94           CurrentDir = dir;
95           FindTargetDir = [];
96           for i=1:length(CurrentDir),
97                dirflag = {CurrentDir.isdir};
98                if dirflag{i} == 1,
99                     SubDirList = {CurrentDir.name};
100                     FindTargetDir = findstr(lower(SubDirList{i}),lower(SrchDirName));
101                     if isempty(FindTargetDir) ~= 1
102                          TargetDirName = SubDirList{i};
103                          cd(TargetDirName);
104                          CurrentDirectory = pwd
105                          break
106                     end
107                end
108           end
109           if isempty(FindTargetDir) == 1,
110                disp('??? Error using ==> cdd');
111                disp('Target directory not found.');
112                disp('  ');
113           end
114      else
115           disp('??? Error using ==> cdd');
116           disp('Invalid wildcard.');
117           disp('  ');
118      end
119 end
120
Note: See TracBrowser for help on using the browser.