Home > p2plib > movedatadirs.m

movedatadirs

PURPOSE ^

move data directories from subdirs of appdir to backdir (for cleanup!)

SYNOPSIS ^

function movedatadirs(appdir,backdir)

DESCRIPTION ^

 move data directories from subdirs of appdir to backdir (for cleanup!) 
 typical call (e.g.): 
 movedatadirs('/home/hu/path/pde2path/demos', '/home/hu/path/data');
 restore data by simply calling movedatadirs(backdir,appdir)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function movedatadirs(appdir,backdir) 
0002 % move data directories from subdirs of appdir to backdir (for cleanup!)
0003 % typical call (e.g.):
0004 % movedatadirs('/home/hu/path/pde2path/demos', '/home/hu/path/data');
0005 % restore data by simply calling movedatadirs(backdir,appdir)
0006 startdir=pwd; 
0007 cd(appdir); ok=0; allok=0; 
0008 md=dir; mdl=length(md); 
0009 for i=1:mdl % first inform user about what's going to happen
0010    cf=md(i); 
0011    if (cf.isdir==1 && ~strcmp(cf.name,'.') && ~strcmp(cf.name,'..'))
0012       cd([appdir,'/',cf.name]); 
0013       subdirs=dir; sdl=length(subdirs); 
0014       for j=1:sdl
0015         csubdir=subdirs(j);
0016         if (csubdir.isdir==1 && ...
0017                ~strcmp(csubdir.name,'.') && ~strcmp(csubdir.name,'..'))
0018            cbackdir=[backdir,'/',cf.name]; 
0019            fprintf('%s: intending to move ', cf.name); 
0020            fprintf('%s to %s \n',csubdir.name,cbackdir);
0021         end
0022       end
0023    end
0024 end
0025 allok=asknu('OK to all?', allok); 
0026 cd(appdir)
0027 for i=1:mdl
0028    cf=md(i); 
0029    if (cf.isdir==1 && ~strcmp(cf.name,'.') && ~strcmp(cf.name,'..'))
0030       cd([appdir,'/',cf.name]); 
0031       subdirs=dir; sdl=length(subdirs); 
0032       for j=1:sdl
0033         csubdir=subdirs(j);
0034         if (csubdir.isdir==1 && ...
0035                ~strcmp(csubdir.name,'.') && ~strcmp(csubdir.name,'..'))
0036            cbackdir=[backdir,'/',cf.name]; 
0037            if ~allok
0038              fprintf('%s: intending to move ', cf.name); 
0039              fprintf('%s to %s   ',csubdir.name,cbackdir);
0040              ok=asknu('OK?',ok); 
0041              if ok
0042                if ~exist(cbackdir,'dir'); mkdir(cbackdir); end              
0043                movefile(csubdir.name, cbackdir);
0044              end
0045            end
0046            if allok
0047                if ~exist(cbackdir,'dir'); mkdir(cbackdir); end              
0048                movefile(csubdir.name, cbackdir);
0049            end
0050         end
0051       end
0052    end
0053 end
0054 cd(startdir); % return to calling directory
0055 end

Generated on Wed 15-Aug-2012 10:09:15 by m2html © 2005