Index: prextra/toolbox_export.m
===================================================================
--- prextra/toolbox_export.m	(revision 145)
+++ prextra/toolbox_export.m	(revision 147)
@@ -7,19 +7,28 @@
 % COPYFLAG:  TRUE: copy, FALSE: just zip. default TRUE
 
-function toolbox_export(toolbox,copyflag,exportdir)
+function toolbox_export(toolbox,copyflag,exportdir,exclude)
 
-
+if nargin < 4, exclude = []; end
 if nargin < 3, exportdir = 'K:\insy\PRLab\Matlab\prtools_export'; end
 if nargin < 2 || isempty(copyflag); copyflag = false; end
+if ischar(exclude), exclude = {exclude}; end 
+
+% check toolbox
+s = which([toolbox '/Contents.m']);
+if isempty(s)
+  error(['Toolbox ' toolbox ' is not found or has no Contents.m file']);
+end
 
 % create temp dir
 zipdir = fullfile(fileparts(which(mfilename)),'tmp');
-if exist(zipdir,'dir') ~= 7
-  mkdir(zipdir);
-end
+makedir(zipdir);
 
-toolboxpath = fileparts(which(fullfile(toolbox,'Contents')));
+% get names and version
+today           = datestr(date,'ddmmmyy');
+toolboxpath     = fileparts(which(fullfile(toolbox,'Contents')));
 [~,toolboxname] = fileparts(toolboxpath);
-toolboxver = ver(toolboxpath);
+toolboxver      = ver(toolboxpath);
+
+% get and set possibly new version number in Content file
 fprintf(1,'    Present %s version is %s\n',toolbox,toolboxver(end).Version);
 pver_new = input(['    Give new version number: [' toolboxver(end).Version '] '],'s');
@@ -28,33 +37,54 @@
 end
 set_version_in_Contents(toolboxpath,pver_new);
-ztoolbox = fullfile(zipdir,[toolbox pver_new '.' today '.zip']);
-zip(ztoolbox,{'*.m'},toolboxpath);
-copyfile(ztoolbox,exportdir);
+
+% zip
+zfilename = [toolbox pver_new '_' today '.zip'];
+ztoolbox  = fullfile(zipdir,zfilename);
+sdir      = dirnames(toolboxpath);
+if ~isempty(exclude)
+  for j=1:numel(exclude)
+    n = strmatch(exclude{j},sdir);
+    if isempty(n)
+      error(['Subdirectory ' exclude{j} ' does not exist'])
+    end
+    sdir(n) = [];
+  end
+end
+zip(ztoolbox,[{'*.m'} sdir{:}],toolboxpath);
+
+% create specific archdir for this toolbox
+archdir = fullfile(exportdir,toolboxname);
+makedir(archdir);
 
 if copyflag
+  % copy to website, use the @ftp package
   ftpsite = ftp('prtools.tudelft.nl','prlab','0iX7&b3c');
   cd(ftpsite,'httpdocs/files');
   mput(ftpsite,ztoolbox);
-  rename(ftpsite,ztoolbox,[toolboxname '.zip']);
-  disp('    export files have been stored on the website.')
+  rename(ftpsite,zfilename,[toolboxname '.zip']);
+  disp('    Export files have been stored on the website.')
   disp('    Please check and adjust release notes and known problems on website')
+  webversion(pver_new,toolboxname,ftpsite); % reset the version file
   close(ftpsite)
   
-  % backup p-files and m-files
+  % backup in exportdir
   fprintf(1,'    Storing backups of mfiles and export files ... \n');
-  [s,mess] = copyfile(ztoolbox,fullfile(exportdir,toolboxname));
+  [s,mess] = copyfile(ztoolbox,archdir);
   if s
-    delete(exppfiles);
-    disp(['    export files have been backed-up in ' exportdir])
+    disp(['    export files have been backed-up in ' archdir])
   else
     disp(mess); 
   end
 else
-  fprintf(1,'    The zip-files have been created in exportdir.\n');
-  fprintf(1,'    They have not been copied to the website!\n');
-  fprintf(1,'    If needed, rerun with flag set.\n');
+  copyfile(ztoolbox,archdir);
+  disp(['    The zip-files have been created in ' archdir]);
+  disp(['    They have not been copied to the website!']);
+  disp(['    If needed, rerun with flag set']);
 end
+% cleanup
+rmdir(zipdir,'s')
 
 function set_version_in_Contents(toolbox,prtv)
+
 if ~isstr(prtv)
 	error('Version should be given as string, e.g. ''3.2.7''')
@@ -62,6 +92,84 @@
 contentfile = fullfile(toolbox,'Contents.m');
 s = readf(contentfile);
-n = findstr(s,prnewline);
+n = findstr(s,newline);
 r = [s(1:n(1)), '% Version ' prtv ' ' date s(n(2):end)];
 writf(contentfile,r);
 disp('    Contents.m rewritten with new version number')
+
+
+function [subdirs,files] = dirnames(dirname,ext)
+%DIRNAMES
+%
+%	[SUBDIRS,FILES]= DIRNAMES(DIR,EXT)
+%
+%Get names of all subdirs and files in direcotory DIR.
+%Hidden files, . and .. and Thumbs.db neglected
+
+if nargin == 0
+  dirname = '.';
+end
+
+if nargin > 1
+  allnames = dir([dirname '/*.' ext]);
+else
+  allnames = dir(dirname);
+end
+n = length(allnames);
+subdirs = cell(1,n);
+files = cell(1,n);
+ns = 0;
+nf = 0;
+
+for j=1:n
+  name = deblank(allnames(j).name);
+	if (name(1) ~= '.') && ~strcmp(name,'Thumbs.db') % skip hidden files
+		if allnames(j).isdir
+			ns = ns+1;
+			subdirs{ns} = name;
+		else
+			nf = nf+1;
+			files{nf} = name;
+		end
+	end
+end
+
+if ns > 0
+	subdirs = char(subdirs(1:ns));
+  subdirs = cellstr(subdirs);
+else 
+	subdirs = [];
+end
+if nf > 0
+	files = char(files(1:nf));
+  files = cellstr(files);
+else
+	files = [];
+end
+
+
+function makedir(name)
+%MAKEDIR make directory if needed
+
+if exist(name,'dir') ~= 7
+  mkdir(name)
+end
+
+function [s,n] = readf(file)
+fid = fopen(file);
+if fid < 0
+	error(['File ' file ' not found, probably wrong directory'])
+end
+[s,n] = fread(fid);
+if isempty(s)
+  error(['File ' file ' could not be read'])
+end
+s = s(:)';
+fclose(fid);
+
+function writf(file,s)
+fid = fopen(file,'w');
+if fid < 0
+	error(['File ' file ' could not be opened for writing'])
+end
+fwrite(fid,s);
+fclose(fid);
