/* REXX tipa */ signal on halt if (RxFuncQuery('SysLoadFuncs')) then do call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' call SysLoadFuncs end parse arg args if( args == '' ) then do say say 'DELTREE v0.2 (c) ruki' say 'Deltree deletes ALL subdirs and files in a directory.' say say 'Usage: deltree [mask] [/Y] [/S]' say say 'If a mask is specified only files (and no directories)' say 'that match it will be deleted. /Y suppresses the query,' say '/S suppresses the output of filenames being deleted.' say exit -2 end dirname = '' mask = '' noquery = 0 G.bequiet = 0 args = normalize_quotes( args ) argn = 0 do while( args \= '' ) parse var args ar args ar = denormalize_quotes( ar ) if( left( ar, 1 ) == '/' ) then do parse upper var ar '/'ar select when ar == 'Y' then noquery = 1 when ar == 'S' then G.bequiet = 1 otherwise nop end iterate end argn = argn + 1 select when argn == 1 then dirname = ar when argn == 2 then mask = ar otherwise nop end end curdir = directory() dir = directory( dirname ) if( dir == '' ) then do if( \G.bequiet ) then say '0D0A'x||'Directory "'dirname'" does not exist.'||'0D0A'x exit 0 end dirname = dir call directory curdir if( \noquery ) then do qstr = '0D0A'x||'Sure to delete' if( mask == '' ) then qstr = qstr' the directory "'dirname'" including ALL files and subdirs?' else qstr = qstr' ALL files matching "'mask'" recursively in the directory "'dirname'"?' if( query( qstr' [Y/N]', 'YN') \= 'Y' ) then exit 0 end G.cdir = 0 G.cfile = 0 if( \G.bequiet ) then say '0D0A'x||'Deleting:'||'0D0A'x call deldir dirname, mask if( \G.bequiet ) then say '0D0A'x||G.cdir' directories, 'G.cfile' files have been deleted.'||'0D0A'x exit 0 deldir: procedure expose G. parse arg dir, mask call SysFileTree dir'\*', 'dirs.', 'DO' call SysFileTree dir'\'mask, 'files.', 'FO' do i = 1 to files.0 if( \G.bequiet ) then say files.i rc = SysFileDelete( files.i ) if( rc \= 0 ) then call error rc, files.i G.cfile = G.cfile + 1 end do i = 1 to dirs.0 call deldir dirs.i, mask end if( mask == '' ) then do if( \G.bequiet ) then say '['dir']' rc = SysRmDir( dir ) if( rc \= 0 ) then call error rc, dir G.cdir = G.cdir + 1 end return error: procedure parse arg rc, file say '0D0A'x||'Error 'rc' deleting "'file'". Aborted.'||'0D0A'x exit rc query: procedure parse arg str, keys call charout, str do until( verify( ch, keys )==0 ) parse upper value SysGetKey( 'NOECHO' ) with ch end say ch return ch /* replaces spaces within quotes with 0x00 and removes them */ normalize_quotes: procedure parse arg str rstr = '' do while( str \= '' ) parse var str head'"'qstr'"'str rstr = rstr||head||translate( qstr, '00'x, '20'x ) end return rstr denormalize_quotes: procedure return translate( arg(1), '20'x, '00'x ) halt: say '0D0A0D0A'x||'Aborted.' exit -1