Mercurial > hg > ltpda
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 function rm_cvs_dir(path_in, rm_file_dir) | |
2 % RM_CVS_DIR Remove recursive directories or files in the search directory | |
3 % | |
4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
5 % | |
6 % DESCRIPTION: RM_CVS_DIR Remove recursive the the handover | |
7 % directories or files in the search directory | |
8 % | |
9 % CALL: rm_cvs_dir(toolbox, 'CVS'); | |
10 % rm_cvs_dir(toolbox, '*.m~'); | |
11 % rm_cvs_dir(toolbox, '*.o'); | |
12 % rm_cvs_dir('/home/diepholz/matlab', 'CVS'); | |
13 % | |
14 % REMARK: rm_cvs_dir(toolbox, 'CVS'); This command will remove the file 'CVS' | |
15 % as well as the directory 'CVS' | |
16 % | |
17 % | |
18 % HISTORY: 24-05-2007 Diepholz | |
19 % Creation | |
20 % | |
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
22 | |
23 | |
24 % Replace the regular expression '*' with '\w*' | |
25 rm_file = strrep(rm_file_dir, '*', '\w*'); | |
26 rm_file = strcat('^', rm_file); | |
27 | |
28 files = dir(path_in); | |
29 | |
30 %% Go through the files in the current directory | |
31 for i = 1:length(files) | |
32 | |
33 if files(i).isdir == 1 | |
34 | |
35 %% Delete a directory if case sensitive matchs | |
36 if (strcmp (files(i).name, rm_file_dir)) | |
37 rm_dir = fullfile(path_in, rm_file_dir); | |
38 | |
39 try | |
40 rmdir (rm_dir, 's'); | |
41 catch | |
42 error (sprintf('### rm_cvs_dir: Can not delete the directory %s',rm_dir )); | |
43 end | |
44 | |
45 %% Go into the subdirectory | |
46 elseif ~(strcmp (files(i).name(1), '.')) | |
47 new_dir = fullfile(path_in, files(i).name); | |
48 rm_cvs_dir(new_dir, rm_file_dir); | |
49 end | |
50 | |
51 else %% the object is a file | |
52 | |
53 match = regexp(files(i).name, rm_file, 'match'); | |
54 | |
55 if ~isempty(match); | |
56 remove_file = fullfile(path_in, files(i).name); | |
57 try | |
58 delete (remove_file); | |
59 catch | |
60 error (sprintf('### rm_cvs_dir: Can not delete the file %s', remove_File)); | |
61 end | |
62 end | |
63 | |
64 end | |
65 | |
66 end | |
67 |