home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / REXXCOPY.ZIP / REXXCOPY.CMD next >
OS/2 REXX Batch file  |  1989-12-14  |  7KB  |  225 lines

  1. /*    */
  2. /* REXXCOPY is an REXX version on COPY that REMOVES files
  3.    from a list that you do NOT want to copy.
  4.  
  5.    Usage: REXXCOPY from_dir  to_dir .
  6.    Where: from_dir is the directory we are copying from
  7.           to_dir   is the target direcory.
  8.  
  9.    The user will be prompted for the files to be excluded
  10.    Entering an empty line will start the actual copy.
  11.    The from and to directories must be fully qualified but
  12.    should NOT end in a backslash [\].
  13. */
  14. /*
  15.     Entering a ? as the first argument will display this message.
  16.     Authors: Bill Dickenson & Mike Sabato at E.I.DuPont
  17.  
  18. */
  19. HELP='?'                           /* set up constants */
  20. NULL = ''
  21. DEFAULT = '.'
  22. FILE_OUT = 'REXXCOPY.TXT'
  23. SPACE = ' '
  24. NO = 1
  25. YES = 0
  26. ABORT='QUIT'
  27. COMPLETE = 0
  28. PROBLEM = 1
  29. SUBDIRECTORY = '<DIR>'
  30.  
  31. /*  Arguments   */
  32. arg from_dir to_dir .
  33.  
  34. call EDITIT                      /* edit  the directory names */
  35. call VALIDIR                     /* Make sure that they exist */
  36. call DESELECT                    /* Remove the names */
  37. call COPYALL                     /* copy all of the remaining names */
  38.  
  39. say 'Copy Complete'
  40.  
  41. return(COMPLETE)                 /* get out cleanly   */
  42.  
  43.  
  44. COPYALL:
  45.  /* if the last character not = \ then make it so */
  46.  
  47.  if substr(from_dir,length(from_dir),1) <> '\'
  48.      then from_dir = from_dir'\'
  49.  if substr(to_dir,length(to_dir),1) <> '\'
  50.      then to_dir = to_dir'\'
  51.  
  52. '@ECHO OFF'                       /* OS/2 command */
  53. say 'Starting copy now ........'
  54. do sub_script = 0 to line_count              /* Copy all non-NULL files */
  55.            if file_list.sub_script = NULL
  56.            then iterate                          /* drop it if NULL */
  57.  
  58.                  /* copy all */
  59.  
  60.                  'COPY 'from_dir||file_list.sub_script  '  ' to_dir'*.* > null'
  61.                   if rc = NO
  62.                      then call ERRORS
  63.  
  64. end
  65. return(0)
  66.  
  67. DESELECT:
  68. input_line = ''
  69. say ; say ;
  70. say 'From Directory is: 'from_dir
  71. say 'To   Directory is: 'to_dir
  72. say
  73. say 'Please input the file names you do not want copied, one at a time'
  74. say 'When you are done, press [ENTER] to complete the copy or type'
  75. say 'QUIT to stop the copy immediatly'
  76. say ' '
  77.  
  78. /*        Do FOREVER is an infinte loop that runs until a
  79.              LEAVE command is executed
  80. */
  81.  
  82. do forever
  83.      say 'File name(s) to exclude. [ENTER] to quit. ? to list files'
  84.      pull input_line
  85.  
  86. /*     Select is a poor mans CASE statement.
  87.        OTHERWISE is the catch all
  88. */
  89.  
  90.      select
  91.       when  input_line = NULL
  92.           then leave                    /* run it */
  93.       when translate(input_line) = ABORT
  94.           then CALL ABORTIT             /* kill it */
  95.       when input_line = HELP
  96.          then  call SHOWALL             /* show all files */
  97.  
  98.    otherwise do I = 1 to Words(input_line)  /* select a file */
  99.                found_it = NO
  100.                do sub_script = 0 to line_count
  101.                      if file_list.sub_script = word(input_line,I)
  102.                             then do
  103.                                     found_it = YES
  104.                                     file_list.sub_script = NULL
  105.                                  end
  106.                end
  107.                if found_it = NO
  108.                   then do
  109.                        say 'Did not find the file 'word(input_line,I)' in the list'
  110.                        say 'Please retry'
  111.                        end
  112.               end
  113.           end
  114. end
  115. return(0)
  116.  
  117. VALIDIR:
  118. current_dir = directory()                /* Save where we are */
  119. '@dir 'from_dir ' > ' FILE_OUT            /* pipe the DIR to a file */
  120. if rc <> 0                               /* check return code */
  121. then call ERRORS                         /* call error message stuff */
  122. sub_script = 0
  123. do x_pos = 1 while lines(file_out)                 /* read the file    */
  124.           file_line = linein(file_out)             /* and store in a temp area  */
  125.           if substr(file_line,1,1) = SPACE         /* is it a SPACE */
  126.           then iterate                           /* get rid of the line */
  127. /*
  128. PARSE is very handy. It takes the variable 'file_line' and breaks it
  129. up into 'filename' 'fileext' based on a space delimiter
  130. */
  131.           parse value file_line with filename fileext  .
  132.           file_list.sub_script = filename'.'fileext
  133.            if fileext = SUBDIRECTORY
  134.            then  file_list.sub_script = NULL
  135.            else  sub_script = sub_script + 1    /* increment */
  136.            end
  137. line_count = sub_script - 1                /* I always increment after */
  138. return(0)
  139.  
  140. /* Help message is here */
  141.  
  142. HELPME:
  143. say ; say ;
  144.        do line = 5 while substr(sourceline(line),1,2) <> '*/'
  145.        say sourceline(line)
  146.        end
  147.        tmpvar=directory(current_dir)      /* restore current directory */
  148.        exit(PROBLEM)
  149.  
  150. /* Do the edits on dir_from and dir_to */
  151.  
  152. EDITIT:
  153.  
  154. r_c = YES
  155. select
  156.   when  length(from_dir) = 0
  157.           then do
  158.           say 'The From directory ('from_dir') is blank or invalid'
  159.           r_c = PROBLEM
  160.           end
  161.   when  length(to_dir) = 0
  162.           then do
  163.           say 'The TO directory ('to_dir') is blank or invalid'
  164.           r_c = PROBLEM
  165.           end
  166.   when from_dir = to_dir
  167.          then do
  168.          say 'From directory ('from_dir ') and the To directory ('to_dir ') cannot be the same'
  169.          r_c = PROBLEM
  170.          end
  171.   otherwise nop
  172.   end
  173. if r_c <> YES
  174. then call helpme
  175. /*    if it failed the above tests then the tests below are meaningless
  176.       if it didn't, they could be very important.
  177. */
  178. cls
  179. say ; say;
  180. /*     If you do not give directory an argument, it returns the
  181.        CURRENT directory, if it gets an argument, it CHANGES directory
  182.        to the argument and sets the result = to the new directory.
  183.        if it fails, it leaves tmpvar alone. So to see if the directory
  184.        exists, I test TMPVAR vs the new directory name
  185. */
  186. current_dir = directory()
  187. if directory(from_dir)<> from_dir
  188.     then do
  189.             say 'The FROM directory ('from_dir') is invalid'
  190.              r_c = PROBLEM
  191.              end
  192. if directory(to_dir) <> to_dir
  193.     then do
  194.             say 'The TO directory ('to_dir') is invalid'
  195.              r_c = PROBLEM
  196.              end
  197.  
  198.  
  199. tmpvar=directory(current_dir)
  200. if r_c = COMPLETE
  201. then return
  202. else call helpme
  203. exit
  204.  
  205.  
  206.  
  207. ABORTIT:
  208. say 'Copy Aborted'
  209. exit(PROBLEM)
  210.  
  211. SHOWALL:
  212.  
  213. do xx = 0 to line_count by 4
  214.      line_display = NULL
  215.      do yy = xx to min(xx+3,line_count)
  216.         line_display = line_display left(file_list.yy,18)
  217.         end
  218.       say line_display
  219.       end
  220. return
  221.  
  222. ERRORS:
  223. say 'Problem with the file 'file_list.sub_script '. Process will continue'
  224. RETURN(PROBLEM)
  225.