function newfolder(thePath)

% newfolder -- Create a new folder (directory).
%  newfolder('thePath') creates a new folder named
%   'thePath' (no embellishments) immediately below
%   the current directory.  The current directory
%   setting itself remains the same.  This task
%   will exit with a warning message if the new
%   folder already exists.  On the Macintosh, the
%   MPW ToolServer is required.

% Copyright (C) 1996-7 Dr. Charles R. Denham, ZYDECO.
%  All Rights Reserved.
%   Disclosure without written explicit consent from the
%    copyright owner does not constitute publication.

if nargin < 1, help newfolder, return, end

warn = 'warning(lasterr); lasterr('''')';

theSystemCommand = '!mkdir';
if any(findstr(computer, 'MAC'))
   theSystemCommand = '!ToolServer NewFolder';
  elseif any(findstr(computer, 'VMS'))
   theSystemCommand = '!create/directory';
end

p = pwd;
itExists = 1;
eval(['cd ' fullfile(pwd, thePath)], 'itExists = 0;')
if itExists
   eval(['cd ' p])
   disp([' ## Aleady exists: ' fullfile(pwd, thePath)])
  else
   eval([theSystemCommand ' ' pwd filesep thePath], warn)
   disp([' ## New directory: ' fullfile(pwd, thePath)])
end
