home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / wwwos2.zip / copyurl.cmd < prev    next >
OS/2 REXX Batch file  |  1998-07-31  |  5KB  |  162 lines

  1. /* Copyright (c)1996 Kari Jackson for InnoVal Systems Solutions, Inc. */
  2. /* To copy or move *.URL (bookmark) files to another WebWilly for OS/2 */
  3. /* folder without 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 "    *.URL to the end of it.  If not a directory, the program will add"
  17.    say "    .URL to the end of it unless it already ends with .URL."
  18.    say "2.  Target file specification:  A directory name.  If omitted, the files"
  19.    say "    will be copied to the current directory.  Either way, the directory"
  20.    say "    must be an existing WebWilly folder."
  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.    do i=1 to first.0
  32.       say first.i
  33.    end
  34.    say ""
  35.    say "Parameter ("firstarg") not understood...."
  36.    say "Multiple directories (above) by that name exist."
  37.    exit
  38. end
  39. if firstarg\="*" & first.0=1 then source=first.1'\*.URL'
  40. if firstarg="*" | first.0=0 then do
  41.    if translate(right(firstarg,4))='.URL' then source=firstarg
  42.    else source=firstarg'.URL'
  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.          do i=1 to check.0
  58.             say check.i
  59.          end
  60.          say ""
  61.          say "Parameter ("target") not understood...."
  62.          say "Multiple directories (above) by that name exist."
  63.          exit
  64.       end
  65.       if check.0=0 then do
  66.          say ""
  67.          say "Directory ("target") does not exist.  Files"
  68.          say "must be copied to an existing WebWilly folder."
  69.          exit
  70.       end
  71.       if check.0=1 then target=check.1
  72.    end
  73. end
  74. title=''
  75. rc=SysGetEA(target,'WEBEXFOLDERNAME','title')
  76. if rc>0 | strip(title)='' then do
  77.    say ""
  78.    say "Directory ("target") is not a WebWilly folder."
  79.    exit
  80. end
  81. if translate(thirdarg)='/M' then move=1
  82. call sysfiletree source,'files','FO'
  83. if files.0=0 then do
  84.    say ""
  85.    say "No" source "file(s) found."
  86.    exit
  87. end
  88. say ""
  89. if right(target,1)='\' then target=substr(target,1,length(target)-1)
  90. do i=1 to files.0
  91.    lastslash=lastpos('\',files.i)+1
  92.    parse var files.i . =(lastslash) filename
  93.    if stream(target'\'filename,'c','query exists')<>'' then do
  94.       parse var filename filename '.' .
  95.       parse var filename five 6 six 7 seven 8 eight
  96.       if length(eight)>1 then do
  97.          say ""
  98.          say "Filename ("filename") is longer than eight characters;"
  99.          say "this is not valid for a *.URL file name.  Skipping this file...."
  100.          say ""
  101.          iterate
  102.       end
  103.       okay=0
  104.       filename=translate(filename)
  105.       characters='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  106.       origpos6=pos(six,characters)
  107.       origpos7=pos(seven,characters)
  108.       origpos8=pos(eight,characters)
  109.       newpos6=origpos6
  110.       newpos7=origpos7
  111.       newchar6=six
  112.       newchar7=seven
  113.       do j=1 to 36 until okay=1
  114.          do k=1 to 36 until okay=1
  115.             do l=1 to 36 until okay=1
  116.                newpos8=(origpos8+l)//36
  117.                if newpos8=0 then newpos8=36
  118.                newchar8=substr(characters,newpos8,1)
  119.                filename=five||newchar6||newchar7||newchar8
  120.                if stream(target'\'filename'.URL','c','query exists')='' then okay=1
  121.             end
  122.             newpos7=(origpos7+k)//36
  123.             if newpos7=0 then newpos7=36
  124.             newchar7=substr(characters,newpos7,1)
  125.          end
  126.          newpos6=(origpos6+j)//36
  127.          if newpos6=0 then newpos6=36
  128.          newchar6=substr(characters,newpos6,1)
  129.       end
  130.       if okay=0 then do
  131.          say ""
  132.          say "There are already 46,656 files in the" target
  133.          say "directory with" five"???.URL filenames!"
  134.          exit
  135.       end
  136.       filename=filename'.URL'
  137.    end
  138.    say files.i "-->" target'\'filename
  139.    call sysfiledelete '$$temp$$.123'
  140.    eautil files.i '$$temp$$.123 /s /p'
  141.    if rc=0 then rc=lineout(target'\'filename)
  142.    if rc=0 then eautil target'\'filename '$$temp$$.123 /j'
  143.    if rc>0 then say '   WARNING:  UNSUCCESSFUL!'
  144.    else if move=1 then call sysfiledelete files.i
  145.    call sysfiledelete '$$temp$$.123'
  146. end
  147. exit
  148. Syntax:
  149.   say 'Error' rc 'in line' sigl':' errortext(rc)
  150.   say sigl':' sourceline(sigl)
  151.   exit
  152. return
  153. Halt:
  154.    say 'CopyUrl.CMD interrupted by Ctrl-C, ShutDown, or closing of WorkArea.'
  155.    exit
  156. return
  157. NoREXX:
  158.    say 'Unable to load the REXXUtil functions.  Either the REXXUTIL.DLL file'
  159.    say 'is not on the LIBPATH or REXX support is not installed on this system.'
  160.    exit
  161. return
  162.