home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / postroad.zip / copypop.cmd < prev    next >
OS/2 REXX Batch file  |  1997-10-23  |  5KB  |  154 lines

  1. /* Copyright (c)1996 Kari Jackson for InnoVal Systems Solutions, Inc. */
  2. /* To copy or move *.POP files to another directory without */
  3. /* overwriting existing files by the same names */
  4. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  5. signal on syntax name NoREXX
  6. call SysLoadFuncs
  7. signal on syntax name Syntax
  8. signal on halt name Halt
  9. '@ECHO OFF'
  10. parse arg firstarg secondarg thirdarg .
  11. if firstarg='' then do
  12.    say ""
  13.    say "Parameters:"
  14.    say "-----------"
  15.    say "1.  Source file specification:  If a directory name, the program will add"
  16.    say "    *.POP to the end of it.  If not a directory, the program will add"
  17.    say "    .POP to the end of it unless it already ends with .POP."
  18.    say "2.  Target file specification:  A directory name.  If omitted, the files"
  19.    say "    will be copied to the current directory.  If specified directory does"
  20.    say "    not exist, it will be created, with permission."
  21.    say "3.  Add an /M switch to the end of the command if you want to move the"
  22.    say "    files rather than copying them."
  23.    exit
  24. end
  25. move=0
  26. first.0=1
  27. if length(firstarg)=3 & right(firstarg,2)=':\' then first.1=left(firstarg,2)
  28. else call sysfiletree firstarg,'first','DO'
  29. if firstarg\="*" & first.0>1 then do
  30.    say ""
  31.    say "Parameter ("firstarg") not understood...."
  32.    say "Multiple directories by that name exist:"
  33.    say ""
  34.    do i=1 to first.0
  35.       say first.i
  36.    end
  37.    exit
  38. end
  39. if firstarg\="*" & first.0=1 then source=first.1'\*.POP'
  40. if firstarg="*" | first.0=0 then do
  41.    if translate(right(firstarg,4))='.POP' then source=firstarg
  42.    else source=firstarg'.POP'
  43. end
  44. select
  45.    when translate(secondarg)='/M' then do
  46.       move=1
  47.       target=directory()
  48.    end
  49.    when secondarg='' then target=directory()
  50.    otherwise do
  51.       target=secondarg
  52.       check.0=1
  53.       if (length(target)=3 & right(target,2)=':\')|(length(target)=2 & right(target,1)=":") then check.1=target
  54.       else call sysfiletree target,'check','DO'
  55.       if check.0>1 then do
  56.          say ""
  57.          say "Parameter ("target") not understood...."
  58.          say "Multiple directories by that name exist:"
  59.          say ""
  60.          do i=1 to check.0
  61.             say check.i
  62.          end
  63.          exit
  64.       end
  65.       if check.0=0 then do
  66.          say ""
  67.          say "Directory ("target") does not exist.  Create it (Y/n)?"
  68.          if translate(sysgetkey())='N' then exit
  69.          if sysmkdir(target)>0 then do
  70.             say ""
  71.             say "Error ("result") trying to create directory ("target")."
  72.             exit
  73.          end
  74.       end
  75.       if check.0=1 then target=check.1
  76.    end
  77. end
  78. if translate(thirdarg)='/M' then move=1
  79. call sysfiletree source,'files','FO'
  80. if files.0=0 then do
  81.    say ""
  82.    say "No" source "file(s) found."
  83.    exit
  84. end
  85. say ""
  86. if right(target,1)='\' then target=substr(target,1,length(target)-1)
  87. do i=1 to files.0
  88.    lastslash=lastpos('\',files.i)+1
  89.    parse var files.i . =(lastslash) filename
  90.    if stream(target'\'filename,'c','query exists')<>'' then do
  91.       parse var filename filename '.' .
  92.       parse var filename five 6 six 7 seven 8 eight
  93.       if length(eight)>1 then do
  94.          say ""
  95.          say "Filename ("filename") is longer than eight characters;"
  96.          say "this is not valid for a *.POP file name.  Skipping this file...."
  97.          say ""
  98.          iterate
  99.       end
  100.       okay=0
  101.       filename=translate(filename)
  102.       characters='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  103.       origpos6=pos(six,characters)
  104.       origpos7=pos(seven,characters)
  105.       origpos8=pos(eight,characters)
  106.       newpos6=origpos6
  107.       newpos7=origpos7
  108.       newchar6=six
  109.       newchar7=seven
  110.       do j=1 to 36 until okay=1
  111.          do k=1 to 36 until okay=1
  112.             do l=1 to 36 until okay=1
  113.                newpos8=(origpos8+l)//36
  114.                if newpos8=0 then newpos8=36
  115.                newchar8=substr(characters,newpos8,1)
  116.                filename=five||newchar6||newchar7||newchar8
  117.                if stream(target'\'filename'.POP','c','query exists')='' then okay=1
  118.             end
  119.             newpos7=(origpos7+k)//36
  120.             if newpos7=0 then newpos7=36
  121.             newchar7=substr(characters,newpos7,1)
  122.          end
  123.          newpos6=(origpos6+j)//36
  124.          if newpos6=0 then newpos6=36
  125.          newchar6=substr(characters,newpos6,1)
  126.       end
  127.       if okay=0 then do
  128.          say ""
  129.          say "There are already 46,656 files in the" target
  130.          say "directory with" five"???.POP filenames!"
  131.          exit
  132.       end
  133.       filename=filename'.POP'
  134.    end
  135.    say files.i "-->" target'\'filename
  136.    'copy' files.i target'\'filename
  137.    if rc=0 & move=1 then call sysfiledelete files.i
  138. end
  139. exit
  140. Syntax:
  141.   say 'Error' rc 'in line' sigl':' errortext(rc)
  142.   say sigl':' sourceline(sigl)
  143.   exit
  144. return
  145. Halt:
  146.    say 'CopyPop.CMD interrupted by Ctrl-C, ShutDown, or closing of WorkArea.'
  147.    exit
  148. return
  149. NoREXX:
  150.    say 'Unable to load the REXXUtil functions.  Either the REXXUTIL.DLL file'
  151.    say 'is not on the LIBPATH or REXX support is not installed on this system.'
  152.    exit
  153. return
  154.