home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
DUPDEL00.ZIP
/
DUPDEL.CMD
next >
Wrap
OS/2 REXX Batch file
|
1992-10-07
|
9KB
|
389 lines
/* dupdel.cmd - Find all duplicate file names on one or multiple
drives, present the names to the user, and delete
any or all based on user input.
Parms are path(s) with the drive letter included and
file filters to look for.
Examples: 'DUPDEL C: *.ZIP'
'DUPDEL C:\OS2 *.INI'
'DUPDEL C: D: E: *.EXE *.COM *.BAT'
The user can chose which duplicate files to delete.
The user will have the option to delete the files
at the end of the routine or create a temporay batch
file to do the deletes after the file is reviewed.
This REXX routine requires the VREXX function package.
Tony Thigpen
115 West York Court
Longwood, FL 32779
Revision 0.0 10/03/92 */
trace off
signal on failure name V_CLEANUP
signal on halt name V_CLEANUP
signal on syntax name V_CLEANUP
signal on error name V_CLEANUP
parse upper source oper.system call.type cmd.file.source .
if oper.system <> 'OS/2'
then call ERROR_MESSAGE '16 001 This REXX routine can only run in OS/2, not' oper.system'.'
parse upper version version
i = lastpos('\',cmd.file.source) + 1
parse var cmd.file.source . =(i) cmd.name '.CMD'
arg args /* args will be parsed out as drive(s) and file filter(s) */
call V_LOAD
call VERIFY_PARMS
call BUILD_FILE_LIST
call SORT_FILES
call REMOVE_NON_DUPS
if file.list.0 = 0 then call ERROR_MESSAGE '6 0001 No duplicate files found'
call SHOW_DUPS
if del.list.0 = 0 then call ERROR_MESSAGE '6 0002 No files selected'
call WHICH_WAY_SCREEN
call RX_LOAD
call DELETE_FILES
call FINISHED_MESSAGE
exit 0
VERIFY_PARMS:
/* Break out drives and file filters from arguments */
parse value ' ' with drives. filters.
parse value 'C: *.*' with drives.1 filters.1
parse value '1 1' with j k
do i = 1 to words(args)
parm = strip(word(args,i),'B')
if substr(parm,2,1) \= ':' /* Must be a drive or path */
then do
filters.k = parm
k = k + 1
iterate
end
drives.j = parm
if \ datatype(left(parm,1),'M') /* Is drive letter valid */
then call ERROR_MESSAGE '16 002 Drive' parm 'is not a valid drive letter'
if right(parm,1) \= '\' then drives.j = drives.j'\'
j = j + 1
end
drives.0 = j - 1
filters.0 = k - 1
return 0
BUILD_FILE_LIST:
file.list. = ' '
file.list.0 = 0
do i = 1 to drives.0
do j = 1 to filters.0
call GET_FILES drives.i filters.j
end
end
return 0
GET_FILES:
arg drive filter
if RxFuncQuery(SysFileTree)
then call RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
call SysFileTree drive||filter, 'files', 'FSO'
if result \= 0
then call ERROR_MESSAGE '16 0003 Not enouth memory to get file tree'
do k = 1 to files.0
file.list.0 = file.list.0 + 1
m = file.list.0
last.slash = lastpos('\',files.k)
filename = substr(files.k,last.slash+1,length(files.k)-last.slash)
filepath = left(files.k,last.slash)
parse upper var filename file.list.name.m
file.list.path.m = filepath
file.list.full.name.m = files.k
end
return 0
SORT_FILES:
done = 'NO'
loops = file.list.0 - 1
do until done = 'YES'
done = 'YES'
do i = 1 to loops
j = i + 1
if file.list.name.i > file.list.name.j
then parse value,
file.list.name.i'^'file.list.path.i'^'file.list.full.name.i||,
'^'file.list.name.j'^'file.list.path.j'^'file.list.full.name.j||,
'^NO' with,
file.list.name.j '^' file.list.path.j '^' file.list.full.name.j,
'^' file.list.name.i '^' file.list.path.i '^' file.list.full.name.i,
'^' done
end
end
return 0
REMOVE_NON_DUPS:
loops = file.list.0 - 1
file.list.dup.1 = 'NO'
do i = 1 to loops
j = i + 1
file.list.dup.j = 'NO'
file.list.dup.end.i = 'YES'
if file.list.name.i = file.list.name.j
then parse value 'YES YES NO' with file.list.dup.i file.list.dup.j,
file.list.dup.end.i
end
i = file.list.0
file.list.dup.end.i = 'YES'
j = 0
do i = 1 to file.list.0
if file.list.dup.i = 'NO' then iterate
j = j + 1
if i = j then iterate
file.list.name.j = file.list.name.i
file.list.path.j = file.list.path.i
file.list.full.name.j = file.list.full.name.i
file.list.dup.j = file.list.dup.i
file.list.dup.end.j = file.list.dup.end.i
end
file.list.0 = j
return 0
SHOW_DUPS:
j = 0
k = 0
m = 0
do i = 1 to file.list.0
j = j + 1
k = k + 1
files.k = file.list.path.i
if file.list.dup.end.i \= 'NO'
then do
call SELECT_SCREEN
iterate
end
if k = 10
then do
call MORE_SCREEN
call SELECT_SCREEN
end
end
del.list.0 = m
return 0
SELECT_SCREEN:
title = file.list.name.i
files.0 = k
win.left = 00
win.right = 100
win.top = 90
win.bottom = 60
win.font = 'COUR'
win.size = '10'
win.forecolor = 'WHITE'
win.backcolor = 'BLACK'
win.id = VOpenWindow(title,win.forecolor,win)
call VSetFont win.id, win
call VBackColor win.id win.backcolor
x = 10
y = 900
do n = 1 to files.0
call VSay win.id, x, y, files.n
y = y - 100
end
diag.centerx = 80
diag.centery = 30
call VDialogPos diag.centerx, diag.centery
title = file.list.name.i
files.0 = k
deletes. = ' '
button = ' '
button = VCheckBox(title,files,deletes,3)
call VCloseWindow win.id
if button = 'CANCEL'
then do
call HOW_CANCEL_SCREEN_1
k = 0
return 0
end
k = 0
do n = 1 to deletes.0
m = m + 1
del.list.m = deletes.n||title
end
return 0
HOW_CANCEL_SCREEN_1:
title = cmd.name '- CANCEL REQUESTED'
msg.line.0 = 5
msg.line.1 = 'You have have selected the CANCEL option.'
msg.line.2 = ''
msg.line.3 = 'If you wish to cancel the' cmd.name 'process'
msg.line.4 = 'then select [YES]. If you select [NO], the'
msg.line.5 = 'last screen will be redisplayed.'
button = ''
button = VMsgBox(title,msg.line,6)
if button = 'YES'
then call ERROR_MESSAGE '8 0004' cmd.name 'Cancled By Operator'
call SELECT_SCREEN
return 0
MORE_SCREEN:
title = cmd.name '- MORE'
msg.line.0 = 5
msg.line.1 = cmd.name 'can only display only 10 duplicate'
msg.line.2 = 'files on each selection screen. When you '
msg.line.3 = 'finish with the next screen, another screen'
msg.line.4 = 'with additonal selections for the same file'
msg.line.5 = 'name will be displayed.'
button = VMsgBox(title,msg.line,1)
return 0
WHICH_WAY_SCREEN:
title = cmd.name '- Process now or later?'
msg.line.0 = 7
msg.line.1 = 'All selections are complete.'
msg.line.2 = ' '
msg.line.3 = 'Do you want the deletes to be'
msg.line.4 = 'performed at this time? If'
msg.line.5 = 'you chose [NO], then a batch'
msg.line.6 = 'file will be created to perform'
msg.line.7 = 'the deletes at a later time.'
delete.now = VMsgBox(title,msg.line,6)
return 0
RUN_IT_MSG:
title = cmd.name
msg.line.0 = 3
msg.line.1 = 'To delete the selected files,'
msg.line.2 = 'run the file -' delfile
msg.line.3 = 'after reviewing the contents.'
button = VMsgBox(title,msg.line,1)
return 0
DELETE_FILES:
if delete.now = 'NO'
then do
delfile = SysTempFileName('C:\DEL!????.CMD')
lo.rx = lineout(delfile,'/* */')
if lo.rx \= 0
then call ERROR_MESSAGE '8 0005 Can not write delete file -' delfile
end
do i = 1 to del.list.0
command = 'rc = SysFileDelete("'del.list.i'")'
if delete.now = 'YES'
then do
interpret command
if rc \= 0
then call ERROR_MESSAGE '4 1'left(rc,3,'0') 'Delete Failed'
end
else do
lo.rx = lineout(delfile,command)
if lo.rx \= 0
then call ERROR_MESSAGE '8 0006 Can not write delete file -' delfile
end
end
if delete.now = 'NO'
then call RUN_IT_MSG
return 0
RX_LOAD:
if \ RxFuncQuery('SysLoadFuncs')
then return 0
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs
return 0
V_LOAD:
if RxFuncQuery(VInit)
then call RxFuncAdd 'Vinit', 'VREXX', 'Vinit'
v.initcode = VInit()
if v.initcode = 'ERROR'
then call ERROR_MESSAGE '16 0007 Can Not Load Visual REXX Functions'
return 0
V_CLEANUP:
if symbol('v.initcode') = 'VAR'
then call VExit
if symbol('em.rc') = 'VAR' then return
exit 9999
ERROR_MESSAGE:
arg em.rc msg
if symbol('v.initcode') = 'VAR'
then call ERROR_MESSAGE_SCREEN
else say msg
if em.rc < 6 then return 0
call V_CLEANUP
exit em.rc
ERROR_MESSAGE_SCREEN:
if em.rc < 8
then type.error = 'non-critical'
else type.error = 'critical'
title = cmd.name
msg.line.0 = 3
msg.line.1 = 'The following' type.error 'error has occured:'
msg.line.2 = ''
msg.line.3 = msg
button = VMsgBox(title,msg.line,1)
return 0
FINISHED_MESSAGE:
title = cmd.name
msg.line.0 = 1
msg.line.1 = cmd.name 'DONE'
if symbol('v.initcode') = 'VAR'
then button = VMsgBox(title,msg.line,1)
else say msg.line.1
return 0