Cleanup.m

From Pnb
Jump to navigation Jump to search
function cleanup()
%created by Erik Stassinos 4/27/2010
%revised 5/18/2010
%should be run in processing folder
%This function goes into the current processing folder and
%removes most of the files created along the way unless the user has specified
%a specific file to be kept or to keep all.  The original files and final files will
%automatically be kept

%cd('test_cleanup')
%cd(pb)

%sprintf('All previous files will be removed except original and final. 
%If you would like to keep a fecific file to look at please enter it.  Do not enter anything if you with to remove all intermediate processing files')
disp('All intermediate processing files will be removed except list and text files')
disp('If there is a file you would like to save, enter its full name with extension(.dat or .lcd) at prompt')
disp('If you would like to save all the files and delete later, enter "all" at prompt')
disp('If no files are to be saved, enter "0"')


tosave = input('What file would you like to save? ','s')
if strncmp(lower(tosave),'all',3) == 1
    disp('keeping all files')
    return
end


pattern1 = fullfile(pwd,'*.lcd');
pattern2 = fullfile(pwd,'*.1'); %used to be .lcd.1
pattern3 = fullfile(pwd,'*.2');
pattern4 = fullfile(pwd,'*.datmatrix');
pattern5 = fullfile(pwd,'*.zcal');
pattern6 = fullfile(pwd,'*.strip');
%pattern7 = fullfile(pwd,'*.ASC.1');
%pattern8 = fullfile(pwd,'*.ASC.2');
%pattern9 = fullfile(pwd,'*.dat');
pattern10 = fullfile(pwd,'*.datmat');

list1 = dir(pattern1);
% for a = 1:size(list1);
%     rm1(a,:) = list1(a).name;
% end;

        for i = 1:size(list1)%3:2:17;
            filename = list1(i).name;
            if strncmp(filename,tosave,length(tosave)) ==1
                continue
            end
            delete(filename);
        end

list2 = dir(pattern2);


        for i = 1:size(list2)%3:2:17;
            filename = list2(i).name;
            if strncmp(filename,tosave,length(tosave)) ==1
                continue
            end
            delete(filename);
        end

list3 = dir(pattern3);


        for i = 1:size(list3)%3:2:17;
            filename = list3(i).name;
            if strncmp(filename,tosave,length(tosave)) ==1
                continue
            end
            delete(filename);
        end

list4 = dir(pattern4);

        for i = 1:size(list4)%3:2:17;
            filename = list4(i).name;
            if strncmp(filename,tosave,length(tosave)) ==1
                continue
            end
            delete(filename);
        end

list5 = dir(pattern5);


        for i = 1:size(list5)%3:2:17;
            filename = list5(i).name;
            if strncmp(filename,tosave,length(tosave)) ==1
                continue
            end
            delete(filename);
        end

list6 = dir(pattern6);

        for i = 1:size(list6)%3:2:17;
            filename = list6(i).name;
            if strncmp(filename,tosave,length(tosave)) ==1
                continue
            end
            delete(filename);
        end
        
%  list7 = dir(pattern7);
% 
% 
%         for i = 1:size(list7)%3:2:17;
%             filename = list7(i).name;
%             if strncmp(filename,tosave,length(tosave)) ==1
%                 continue
%             end
%             delete(filename);
%         end       
%         
%  list8 = dir(pattern8);
% 
% 
%         for i = 1:size(list8)%3:2:17;
%             filename = list8(i).name;
%             if strncmp(filename,tosave,length(tosave)) ==1
%                 continue
%             end
%             delete(filename);
%         end       
        
%  list9 = dir(pattern9);
% 
% 
%         for i = 1:size(list9)%3:2:17;
%             filename = list9(i).name;
%             if strncmp(filename,tosave,length(tosave)) ==1
%                 continue
%             end
%             delete(filename);
%         end       
        
 list10 = dir(pattern10);


        for i = 1:size(list10)%3:2:17;
            filename = list10(i).name;
            if strncmp(filename,tosave,length(tosave)) ==1
                continue
            end
            delete(filename);
        end          
        
        
        fclose all;
disp('Cleanup done')
        
        
        

cleanup