home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
REXXCOPY.ZIP
/
REXXCOPY.CMD
next >
Wrap
OS/2 REXX Batch file
|
1989-12-14
|
7KB
|
225 lines
/* */
/* REXXCOPY is an REXX version on COPY that REMOVES files
from a list that you do NOT want to copy.
Usage: REXXCOPY from_dir to_dir .
Where: from_dir is the directory we are copying from
to_dir is the target direcory.
The user will be prompted for the files to be excluded
Entering an empty line will start the actual copy.
The from and to directories must be fully qualified but
should NOT end in a backslash [\].
*/
/*
Entering a ? as the first argument will display this message.
Authors: Bill Dickenson & Mike Sabato at E.I.DuPont
*/
HELP='?' /* set up constants */
NULL = ''
DEFAULT = '.'
FILE_OUT = 'REXXCOPY.TXT'
SPACE = ' '
NO = 1
YES = 0
ABORT='QUIT'
COMPLETE = 0
PROBLEM = 1
SUBDIRECTORY = '<DIR>'
/* Arguments */
arg from_dir to_dir .
call EDITIT /* edit the directory names */
call VALIDIR /* Make sure that they exist */
call DESELECT /* Remove the names */
call COPYALL /* copy all of the remaining names */
say 'Copy Complete'
return(COMPLETE) /* get out cleanly */
COPYALL:
/* if the last character not = \ then make it so */
if substr(from_dir,length(from_dir),1) <> '\'
then from_dir = from_dir'\'
if substr(to_dir,length(to_dir),1) <> '\'
then to_dir = to_dir'\'
'@ECHO OFF' /* OS/2 command */
say 'Starting copy now ........'
do sub_script = 0 to line_count /* Copy all non-NULL files */
if file_list.sub_script = NULL
then iterate /* drop it if NULL */
/* copy all */
'COPY 'from_dir||file_list.sub_script ' ' to_dir'*.* > null'
if rc = NO
then call ERRORS
end
return(0)
DESELECT:
input_line = ''
say ; say ;
say 'From Directory is: 'from_dir
say 'To Directory is: 'to_dir
say
say 'Please input the file names you do not want copied, one at a time'
say 'When you are done, press [ENTER] to complete the copy or type'
say 'QUIT to stop the copy immediatly'
say ' '
/* Do FOREVER is an infinte loop that runs until a
LEAVE command is executed
*/
do forever
say 'File name(s) to exclude. [ENTER] to quit. ? to list files'
pull input_line
/* Select is a poor mans CASE statement.
OTHERWISE is the catch all
*/
select
when input_line = NULL
then leave /* run it */
when translate(input_line) = ABORT
then CALL ABORTIT /* kill it */
when input_line = HELP
then call SHOWALL /* show all files */
otherwise do I = 1 to Words(input_line) /* select a file */
found_it = NO
do sub_script = 0 to line_count
if file_list.sub_script = word(input_line,I)
then do
found_it = YES
file_list.sub_script = NULL
end
end
if found_it = NO
then do
say 'Did not find the file 'word(input_line,I)' in the list'
say 'Please retry'
end
end
end
end
return(0)
VALIDIR:
current_dir = directory() /* Save where we are */
'@dir 'from_dir ' > ' FILE_OUT /* pipe the DIR to a file */
if rc <> 0 /* check return code */
then call ERRORS /* call error message stuff */
sub_script = 0
do x_pos = 1 while lines(file_out) /* read the file */
file_line = linein(file_out) /* and store in a temp area */
if substr(file_line,1,1) = SPACE /* is it a SPACE */
then iterate /* get rid of the line */
/*
PARSE is very handy. It takes the variable 'file_line' and breaks it
up into 'filename' 'fileext' based on a space delimiter
*/
parse value file_line with filename fileext .
file_list.sub_script = filename'.'fileext
if fileext = SUBDIRECTORY
then file_list.sub_script = NULL
else sub_script = sub_script + 1 /* increment */
end
line_count = sub_script - 1 /* I always increment after */
return(0)
/* Help message is here */
HELPME:
say ; say ;
do line = 5 while substr(sourceline(line),1,2) <> '*/'
say sourceline(line)
end
tmpvar=directory(current_dir) /* restore current directory */
exit(PROBLEM)
/* Do the edits on dir_from and dir_to */
EDITIT:
r_c = YES
select
when length(from_dir) = 0
then do
say 'The From directory ('from_dir') is blank or invalid'
r_c = PROBLEM
end
when length(to_dir) = 0
then do
say 'The TO directory ('to_dir') is blank or invalid'
r_c = PROBLEM
end
when from_dir = to_dir
then do
say 'From directory ('from_dir ') and the To directory ('to_dir ') cannot be the same'
r_c = PROBLEM
end
otherwise nop
end
if r_c <> YES
then call helpme
/* if it failed the above tests then the tests below are meaningless
if it didn't, they could be very important.
*/
cls
say ; say;
/* If you do not give directory an argument, it returns the
CURRENT directory, if it gets an argument, it CHANGES directory
to the argument and sets the result = to the new directory.
if it fails, it leaves tmpvar alone. So to see if the directory
exists, I test TMPVAR vs the new directory name
*/
current_dir = directory()
if directory(from_dir)<> from_dir
then do
say 'The FROM directory ('from_dir') is invalid'
r_c = PROBLEM
end
if directory(to_dir) <> to_dir
then do
say 'The TO directory ('to_dir') is invalid'
r_c = PROBLEM
end
tmpvar=directory(current_dir)
if r_c = COMPLETE
then return
else call helpme
exit
ABORTIT:
say 'Copy Aborted'
exit(PROBLEM)
SHOWALL:
do xx = 0 to line_count by 4
line_display = NULL
do yy = xx to min(xx+3,line_count)
line_display = line_display left(file_list.yy,18)
end
say line_display
end
return
ERRORS:
say 'Problem with the file 'file_list.sub_script '. Process will continue'
RETURN(PROBLEM)