1 |
function makedir(varargin) |
---|
2 |
|
---|
3 |
% makedir -- Make a new directory. |
---|
4 |
% makedir('thePath') creates a new sub-directory named 'thePath' |
---|
5 |
% (no embellishments), located within the current directory. |
---|
6 |
% A dialog is invoked if manual intervention is needed. No |
---|
7 |
% action is taken if the desired directory already exists. |
---|
8 |
% The "present-working-directory" itself remains the same. |
---|
9 |
% makedir "p q r" assumes that the arguments represent one |
---|
10 |
% path-name with single-blanks between components. |
---|
11 |
% makedir p q r is the same as makedir "p q r". |
---|
12 |
|
---|
13 |
% Copyright (C) 1996-7 Dr. Charles R. Denham, ZYDECO. |
---|
14 |
% All Rights Reserved. |
---|
15 |
% Disclosure without written explicit consent from the |
---|
16 |
% copyright owner does not constitute publication. |
---|
17 |
|
---|
18 |
% Version of 08-Jul-1997 08:36:09. |
---|
19 |
% Revised 04-Nov-1998 21:57:53. |
---|
20 |
% Revised 05-Nov-1998 15:24:50. |
---|
21 |
|
---|
22 |
if nargin < 1, help(mfilename), return, end |
---|
23 |
|
---|
24 |
thePath = ''; |
---|
25 |
for i = 1:length(varargin) |
---|
26 |
if i > 1, thePath = [thePath ' ']; end |
---|
27 |
thePath = [thePath varargin{i}]; |
---|
28 |
end |
---|
29 |
|
---|
30 |
if thePath(1) == '"' & thePath(length(thePath)) == '"' |
---|
31 |
thePath = thePath(2:length(thePath)-1); |
---|
32 |
end |
---|
33 |
|
---|
34 |
itExists = 1; |
---|
35 |
trystr = 'cd(thePath); cd ..'; |
---|
36 |
catchstr = 'itExists = 0;'; |
---|
37 |
eval(trystr, catchstr) |
---|
38 |
if itExists |
---|
39 |
disp([' ## Directory already exists: "' thePath '"']) |
---|
40 |
return |
---|
41 |
end |
---|
42 |
|
---|
43 |
lasterr('') |
---|
44 |
warn = 'warning(lasterr); lasterr('''');'; |
---|
45 |
|
---|
46 |
thePWD = pwd; |
---|
47 |
if thePWD(length(thePWD)) == filesep |
---|
48 |
thePWD(length(thePWD)) = ''; |
---|
49 |
end |
---|
50 |
|
---|
51 |
if exist('mkdir', 'builtin') | exist('mkdir', 'file') |
---|
52 |
theCommand = ['mkdir(''' thePath ''')']; |
---|
53 |
elseif any(findstr(computer, 'MAC')) |
---|
54 |
theCommand = ['newfolder(''' thePath ''')']; |
---|
55 |
elseif any(findstr(computer, 'VMS')) |
---|
56 |
theCommand = ['!create/directory "' thePWD filesep thePath '"']; |
---|
57 |
else |
---|
58 |
theCommand = ['!mkdir "' thePWD filesep thePath '"']; |
---|
59 |
end |
---|
60 |
|
---|
61 |
disp([' ## ' theCommand]) |
---|
62 |
eval(theCommand, warn) |
---|
63 |
|
---|
64 |
trystr = 'itExists = 1; cd(thePath); cd ..'; |
---|
65 |
catchstr = 'itExists = 0;'; |
---|
66 |
eval(trystr, catchstr) |
---|
67 |
|
---|
68 |
if itExists |
---|
69 |
disp([' ## Directory created: "' thePath '"']) |
---|
70 |
return |
---|
71 |
end |
---|
72 |
|
---|
73 |
thePrompt = ['Make New ' thePath ' Folder']; |
---|
74 |
theInstruction = 'Create, Then Save'; |
---|
75 |
while ~itExists |
---|
76 |
if any(uisetdir(thePrompt, theInstruction)) |
---|
77 |
cd .. |
---|
78 |
eval(trystr, catchstr) |
---|
79 |
else |
---|
80 |
break |
---|
81 |
end |
---|
82 |
thePrompt = [thePrompt '!']; |
---|
83 |
end |
---|
84 |
|
---|
85 |
if itExists |
---|
86 |
disp([' ## Directory created: "' thePath '"']) |
---|
87 |
else |
---|
88 |
disp([' ## Unable to create: "' thePath '"']) |
---|
89 |
end |
---|
90 |
|
---|
91 |
function theResult = newfolder(theFolderName) |
---|
92 |
|
---|
93 |
% newfolder -- Create a new Macintosh folder. |
---|
94 |
% newfolder('theFolderName') creates a new Macintosh |
---|
95 |
% folder of 'theFolderName' in the current directory. |
---|
96 |
% The current directory setting remains unchanged. |
---|
97 |
% If the folder already exists, no action is taken. |
---|
98 |
% The result is logical(1) if successful; otherwise |
---|
99 |
% it is logical(0). |
---|
100 |
|
---|
101 |
% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. |
---|
102 |
% All Rights Reserved. |
---|
103 |
% Disclosure without explicit written consent from the |
---|
104 |
% copyright owner does not constitute publication. |
---|
105 |
|
---|
106 |
% Version of 05-Sep-1997 17:01:27. |
---|
107 |
|
---|
108 |
% The applescript commands in file "newfolder.mac". |
---|
109 |
% |
---|
110 |
% set theTarget to thePath & ":" & theNewFolder |
---|
111 |
% if not (exists item theTarget) then |
---|
112 |
% make new folder at folder thePath |
---|
113 |
% set name of folder "untitled folder" of folder thePath to theNewFolder |
---|
114 |
% end if |
---|
115 |
|
---|
116 |
if nargin < 1 |
---|
117 |
help(mfilename) |
---|
118 |
return |
---|
119 |
end |
---|
120 |
|
---|
121 |
if ~any(findstr(computer, 'MAC')) |
---|
122 |
disp([' ## No action taken: "' mfilename '" requires Macintosh computer.']) |
---|
123 |
return |
---|
124 |
end |
---|
125 |
|
---|
126 |
thePath = pwd; |
---|
127 |
while thePath(length(thePath)) == filesep |
---|
128 |
thePath(length(thePath)) = ''; |
---|
129 |
end |
---|
130 |
thePath = ['"' thePath '"']; |
---|
131 |
|
---|
132 |
theNewFolder = ['"' theFolderName '"']; |
---|
133 |
|
---|
134 |
result = feval('applescript', 'newfolder.mac', ... |
---|
135 |
'thePath', thePath, 'theNewFolder', theNewFolder); |
---|
136 |
|
---|
137 |
if ~isempty(result), disp(result), end |
---|
138 |
|
---|
139 |
result = logical(isempty(result)); |
---|
140 |
|
---|
141 |
if nargout > 0, theResult = result; end |
---|
142 |
|
---|
143 |
function theStatus = uisetdir(thePrompt, theInstruction) |
---|
144 |
|
---|
145 |
% uisetdir -- Open the destination folder via dialog. |
---|
146 |
% uisetdir('thePrompt', 'theInstruction') presents the "uiputfile" |
---|
147 |
% dialog with 'thePrompt' and 'theInstruction', for selecting the |
---|
148 |
% desired destination folder. The returned status is logical(1) |
---|
149 |
% if successful; otherwise, logical(0). |
---|
150 |
|
---|
151 |
% Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. |
---|
152 |
% All Rights Reserved. |
---|
153 |
% Disclosure without explicit written consent from the |
---|
154 |
% copyright owner does not constitute publication. |
---|
155 |
|
---|
156 |
% Version of 03-Jul-1997 09:16:00. |
---|
157 |
|
---|
158 |
if nargin < 1, thePrompt = 'Open The Destination Folder'; end |
---|
159 |
if nargin < 2, theInstruction = 'Save If Okay'; end |
---|
160 |
|
---|
161 |
theFile = 0; thePath = 0; |
---|
162 |
[theFile, thePath] = uiputfile(theInstruction, thePrompt); |
---|
163 |
|
---|
164 |
status = 0; |
---|
165 |
if isstr(thePath) & any(thePath) |
---|
166 |
status = 1; |
---|
167 |
eval('cd(thePath)', 'status = 0;') |
---|
168 |
end |
---|
169 |
|
---|
170 |
if nargout > 0, theStatus = any(any(status)); end |
---|