home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
rexxlb.zip
/
SAMPLES
/
BLAST.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1993-01-09
|
4KB
|
119 lines
/*****************************************************************************/
/* */
/* BLAST: obliterate a directory and all subdirectories. BLAST recursively */
/* deletes all files and subdirectories of a specified directory. The user */
/* is prompted if hidden, system, or read-only files are encountered. */
/* */
/* Requires Personal REXX or REXXLIB (parsefn, dosfname, dosisdir, dosdir, */
/* dosdirpos, doschmod, upper, lower, dosdel, dosrmdir, doscd functions). */
/* functions). */
/* */
/* Command format: BLAST <directory> */
/* */
/*****************************************************************************/
parse arg target .
if target = '' then do
say 'Enter name of directory:'
parse pull target
if target = '' then do
say 'You had second thoughts about it. OK.'
exit
end
end
say 'Warning!' target 'and all its subdirectories will be purged!'
say 'OK to continue (y/n)?'
parse upper pull ok
if \abbrev('YES', ok, 1) then do
say target 'has been spared.'
exit
end
call blast target
exit
/* recursive subroutine to delete directories */
blast: procedure
dirname = arg(1)
parse value parsefn(dirname) with . . fn ft
if fn \= '-' then do
fullname = dosfname(dirname)
if fullname = '' then do
say 'Invalid name:' dirname
return 1
end
end
else
fullname = dirname
if \dosisdir(fullname) then do
say 'Not a directory:' fullname
return 2
end
searchid = make_name(fullname, '*.*')
/* first pass: get rid of all subdirectories */
file = dosdir(searchid, 'na', 'dh', 'd')
do while file \= ''
dirpos = dosdirpos()
parse var file subdir attr
if subdir \= '.' & subdir \= '..' then do
if pos('H', upper(attr)) \= 0 then do
say make_name(fullname, subdir) 'is a hidden directory.'
say 'OK to continue (y/n)?'
parse upper pull ok
if \abbrev('YES', ok, 1) then
return 3
end
call blast make_name(fullname, subdir)
if result \= 0 then
return 4
end
file = dosdir(, 'na', 'dh', 'd', dirpos)
end
/* second pass: get rid of files */
file = dosdir(searchid, 'na', 'sh')
do while file \= ''
parse var file fn attr
fileid = make_name(fullname, fn)
if verify(upper(attr), 'HSR', 'm') \= 0 then do
say fileid 'has read-only, system, or hidden attribute.'
say 'OK to continue (y/n)?'
parse upper pull ok
if \abbrev('YES', ok, 1) then
return 5
call doschmod fileid, , 'hsr'
end
if dosdel(fileid) \= 1 then do
say 'Error deleting' fileid
return 6
end
file = dosdir(, 'na', 'sh')
end
/* finally, delete the directory */
parse value parsefn(fullname) with disk dir . .
if disk \= '-' then
curdir = doscd(disk)
if dir = '\' then
return 0
dir = strip(dir, 't', '\')
if lower(curdir) = lower(dir) then
'cd' disk':..'
call dosrmdir fullname
if dosisdir(fullname) then do
say 'Error removing' fullname
return 7
end
say fullname 'blasted.'
return 0
/* make a name out of path and file id */
make_name: procedure
parse arg path, name
if right(path, 1) = '\' | right(path, 1) = ':' then
return path||name
else
return path'\'name