0001 function [flag] = cleantempdir_yp(owner,year,month,day)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 if nargin > 4,error('Wrong number of input arguments in cleantempdir_yp.m');end
0024 if nargin == 0,owner = getenv('USER');end
0025 if nargin <= 1,datenum_ref = now;end
0026 if nargin == 2,month = 1;day = 1;datenum_ref = datenum(year,month,day);end
0027 if nargin == 3,day = 1;datenum_ref = datenum(year,month,day);end
0028 if nargin == 4,datenum_ref = datenum(year,month,day);end
0029
0030 dkepath = load_structures_yp('dkepath','','');
0031
0032 flag = 0;
0033
0034 dirini = pwd;
0035 if isempty(dkepath.temppathroot) || strcmp(dkepath.temppathroot,pwd),
0036 disp('WARNING: you cannot delete automatically working directories if the parent directory is your local directory !');
0037 return;
0038 end
0039
0040 if isempty(strfind(dkepath.temppathroot,'scratch')) && isempty(strfind(dkepath.temppathroot,'tmp')),
0041 disp('WARNING: you cannot delete automatically working directories if the parent directory is not named ''scratch'' or ''tmp'' !');
0042 return;
0043 end
0044
0045 cd(dkepath.temppathroot);
0046
0047 dirlist = dir;
0048 for idir = 1:length(dirlist),
0049 list = ls('-al');
0050 if dirlist(idir).isdir,
0051 if ~isempty(strfind(list(1:strfind(list,dirlist(idir).name)),owner)),
0052 if dirlist(idir).datenum <= datenum_ref,
0053 flag = flag + rmdir(dirlist(idir).name,'s');
0054 end
0055 end
0056 end
0057 end
0058
0059 if ~nargout,disp(['---> ',int2str(flag),' directories have been deleted in ',dkepath.temppathroot]);end
0060
0061 cd(dirini);
0062