home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 164.lha / ARexx / Example_ARexx / Reformat.rexx < prev    next >
OS/2 REXX Batch file  |  1988-04-28  |  4KB  |  128 lines

  1. /*
  2.     A utility that will convert ARCED,ZOOED or PAKED
  3.     files into either of the other 2 formats you request
  4.     and place it beside the original file in the new compacted format.
  5.     It handles the tedious task automatically and interactively.
  6.     NB: the full path must be given for the location of 
  7.         file to be converted - e.g. df1:testing/one/time.arc
  8.         Also requires that ARC,ZOO and PAK be in the C: directory. 
  9.     As much error checking has been built in as possible.
  10.                 August 13, 1988 - Basil 71361,2622
  11. */
  12.  
  13. parse upper arg x
  14. LF='0A'x
  15.  
  16.     /* establish a position for the dot suffix */
  17.  
  18. Dotposition=length(x)-3
  19.  
  20.     /*  check if the user has got the program call correct */
  21.  
  22. call pathcheck
  23.  
  24.     /*  now make the new ram: directory and copy the file to it */
  25.  
  26. if  exists('ram:formatdir') then address command 'delete ram:formatdir all'
  27. if ~exists('ram:formatdir') then address command 'makedir ram:formatdir'
  28. address command 'copy ' x 'to ram:formatdir'
  29.  
  30.     /*  find out what format the user wants it to be in */
  31.  
  32. selectchoice:
  33. say ""
  34. say "What file format do you wish to be used for compression? "
  35. say "     1)=ARC"
  36. say "     2)=ZOO"
  37. say "     3)=PAK"
  38. say "     4)=Exit please - changed my mind"
  39. pull fformat
  40. select 
  41.   when fformat=1 then newsuffix=".ARC"
  42.   when fformat=2 then newsuffix=".ZOO"
  43.   when fformat=3 then newsuffix=".PAK"
  44.   when fformat=4 then exit
  45.   otherwise say "Your answer must be 1, 2, 3 or 4 only"
  46. end 
  47. if fformat<1 | fformat>3 then call selectchoice
  48.  
  49.     /*  now decompress the file to its components. */
  50.  
  51. if Ending='.ARC' then 
  52.   do
  53.     address command 'cd ram:formatdir'LF'arc x ' file LF'delete' file
  54.   end
  55. else if Ending='.ZOO' then
  56.   do
  57.     address command 'cd ram:formatdir'LF'zoo x ' file LF'delete' file
  58.   end
  59. else address command 'cd ram:formatdir'LF file LF'delete' file
  60. newfile=left(file,(length(file)-4)) || newsuffix
  61. contents=showdir('ram:formatdir')
  62.  
  63.     /* put it all together and replace it */
  64.  
  65. select
  66.   when fformat=1 then address command 'cd ram:formatdir'LF'arc a 'newfile contents
  67.   when fformat=2 then address command 'cd ram:formatdir'LF'zoo a 'newfile contents
  68.   when fformat=3 then address command 'cd ram:formatdir'LF'pak 'newfile contents
  69. end
  70. address command 'cd ram:formatdir'LF'copy 'newfile 'to 'path
  71. address command 'delete ram:formatdir all'
  72. exit
  73.  
  74.     /* ********************* END OF PROGRAM ********************* */
  75.  
  76. pathcheck:
  77.  
  78.     /*  break the name down separately into the path and the file names */
  79.  
  80.   if (lastpos('/',x) >0) | (lastpos(':',x) >0) then
  81.     do 
  82.       if (lastpos('/',x) >0) then pos=lastpos('/',x)
  83.       else pos=lastpos(':',x)
  84.       path=substr(x,1,pos)
  85.       file=substr(x,pos+1)
  86.     end
  87.  
  88.     /*  check to see if there is an argument entered */
  89.  
  90. if (x = "") | (length(file) <=4) then
  91.   do 
  92.     say ' '
  93.     say 'usage = rx pakall VOL:Arcfile.ARC'
  94.     say '  or    rx pakall VOL:Zoofile.ZOO'
  95.     say '  or    rx pakall VOL:Pakfile.PAK'
  96.     say '     where Arcfile.ARC/Zoofile.ZOO/Pakfile.PAK is the file to be Converted.'
  97.     say '     and VOL: is DF0: DF1: or DF2: etc (include full path)'
  98.     say '      ... the rest will be interactive.'
  99.     exit
  100.   end
  101.  
  102.     /*  there must be a volume added in */
  103.  
  104. if (lastpos(':',x)=0) then 
  105.   do
  106.     say "You must include the volume name, e.g. 'DF1:' or 'ARC:' in the path"
  107.     exit
  108.   end
  109.  
  110.     /*  does the file exist? */
  111.  
  112. if ~exists(x) then 
  113.   do
  114.     say x 'not found'
  115.     exit
  116.   end
  117.  
  118.     /*  and finally, is the correct suffix used? */
  119.  
  120. Ending=substr(x,Dotposition,4)
  121. if ~(Ending = '.ARC' | Ending = '.ZOO' | Ending = '.PAK') then 
  122.   do
  123.     say x "does not have the right suffix."
  124.     exit
  125.   end
  126. return
  127.  
  128.