Mercurial > hg > ltpda
diff m-toolbox/rm_cvs_dir.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/rm_cvs_dir.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,67 @@ +function rm_cvs_dir(path_in, rm_file_dir) +% RM_CVS_DIR Remove recursive directories or files in the search directory +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% DESCRIPTION: RM_CVS_DIR Remove recursive the the handover +% directories or files in the search directory +% +% CALL: rm_cvs_dir(toolbox, 'CVS'); +% rm_cvs_dir(toolbox, '*.m~'); +% rm_cvs_dir(toolbox, '*.o'); +% rm_cvs_dir('/home/diepholz/matlab', 'CVS'); +% +% REMARK: rm_cvs_dir(toolbox, 'CVS'); This command will remove the file 'CVS' +% as well as the directory 'CVS' +% +% +% HISTORY: 24-05-2007 Diepholz +% Creation +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +% Replace the regular expression '*' with '\w*' +rm_file = strrep(rm_file_dir, '*', '\w*'); +rm_file = strcat('^', rm_file); + +files = dir(path_in); + +%% Go through the files in the current directory +for i = 1:length(files) + + if files(i).isdir == 1 + + %% Delete a directory if case sensitive matchs + if (strcmp (files(i).name, rm_file_dir)) + rm_dir = fullfile(path_in, rm_file_dir); + + try + rmdir (rm_dir, 's'); + catch + error (sprintf('### rm_cvs_dir: Can not delete the directory %s',rm_dir )); + end + + %% Go into the subdirectory + elseif ~(strcmp (files(i).name(1), '.')) + new_dir = fullfile(path_in, files(i).name); + rm_cvs_dir(new_dir, rm_file_dir); + end + + else %% the object is a file + + match = regexp(files(i).name, rm_file, 'match'); + + if ~isempty(match); + remove_file = fullfile(path_in, files(i).name); + try + delete (remove_file); + catch + error (sprintf('### rm_cvs_dir: Can not delete the file %s', remove_File)); + end + end + + end + +end +