home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / CFIT.CMD < prev    next >
OS/2 REXX Batch file  |  1993-01-04  |  3KB  |  125 lines

  1. /* CFIT.CMD -- OS/2 2.0 ONLY */
  2.  
  3. /*
  4.  
  5.    Invoke with "cfit filespec targetdrive"
  6.  
  7.    filespec can be any valid filespec, with wildcards as desired.  
  8.      It will default to "*.*"
  9.  
  10.    targetdrive would normally be A: or B: but could, I suppose, be
  11.      a hard drive - it will default to 'A:'
  12.  
  13.    For example, to copy all zip files from the current directory to
  14.    the A: drive, enter
  15.                  "cfit *.zip a:"
  16.    cfit will fit as many zip files on a diskette as possible,
  17.    then pause to allow you to insert a new one.
  18.  
  19.  
  20.    Copies files from the current directory to a target drive, 
  21.    presumably a diskette, and allows user to switch volumes when
  22.    there is no more room on the target.  I always felt the native
  23.    copy command should have enough smarts to do this, but it don't.
  24.    Currently, CFIT just copies the files in the order returned by
  25.    the DIR command, with no attempt at a "best fit" kinda thing.
  26.    Maybe later.
  27.    This is just an attempt to introduce a little convenience.  Use
  28.    it if you cfit (sorry).
  29.  
  30.    Author: Walt Herridge
  31.    CIS:    71045,1651
  32.    GEnie:  W.HERRIDGE
  33. */
  34.  
  35. '@echo off'
  36. parse upper arg fileSpec drive trace
  37. if fileSpec = '' then
  38.   fileSpec = '*.*'
  39. if drive = '' then
  40.   drive = 'A:' 
  41.  
  42. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  43. call SysLoadFuncs
  44.  
  45. if trace = 'T' then
  46.   trace ?i
  47.  
  48. if LENGTH(drive) > 2 then
  49.   do
  50.     say drive 'is not a valid drive specification.'
  51.     exit
  52.   end
  53. if LENGTH(drive) > 1 then
  54.   do
  55.     parse var drive driveLetter ':' colon +1
  56.     if colon \= ':' then
  57.       do
  58.         say drive 'is not a valid drive specification.'
  59.         exit
  60.       end
  61.   end
  62. else
  63.   driveLetter = drive
  64. drive = driveLetter || ':'
  65. if \DATATYPE(driveLetter, 'U') then
  66. do
  67.   say drive 'is not a valid drive specification.'
  68.   exit
  69. end
  70.  
  71.  
  72. map = SysDriveMap('A:')
  73.  
  74. if WORDPOS(drive, map) = 0 then
  75.   do
  76.     say drive 'is not a valid drive specification.'
  77.     exit
  78.   end
  79.  
  80. queueName = rxqueue('Create')    /* use our own queue */
  81. call rxqueue 'Set', queueName
  82.  
  83. '@DIR' fileSpec '/N | RXQUEUE' queueName '/FIFO'
  84. do 5                /* discard header lines */
  85.   pull .
  86. end
  87.  
  88. restart = 0
  89.  
  90. do queued() - 2
  91.   if \restart then
  92.     parse pull . . size eaSize name .
  93.   restart = 0
  94.   if size = '<DIR>' then
  95.     iterate
  96.   if eaSize > 0 then
  97.     tSize = size + eaSize + 500     /* guess at ea overhead */
  98.   else
  99.     tSize = size
  100.   parse value SysDriveInfo(drive) with drive free total label
  101.   if tSize > total then
  102.     do
  103.       say 'File' name 'will not fit on target medium - skipped.'
  104.       iterate
  105.     end
  106.   if tSize > free then
  107.     do
  108.       freq = 262
  109.       do 2
  110.         call Beep freq,150
  111.         freq = 294
  112.       end
  113.       say 'No more files will fit on' drive 'drive.'
  114.       say 'Insert new disk and press any key when ready.'    
  115.       parse value SysGetKey('NOECHO') with .
  116.       restart = 1 
  117.       iterate
  118.     end
  119.   say 'Copying' name 'to' drive
  120.   '@COPY' name drive
  121. end
  122.  
  123. call rxqueue 'Delete', queueName
  124. exit
  125.