home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / addupeas.zip / ADDUPEAS.CMD
OS/2 REXX Batch file  |  1995-04-30  |  6KB  |  140 lines

  1. /* ADDUPEAS.CMD This REXX program looks at specified drive */
  2. /* and lists all files to determine the total amount of    */
  3. /* EA space that should be used on the drive in file       */
  4. /* EA DATA. SF given that each EA takes one cluster of     */
  5. /* a FAT formatted disk. This will not match exactly the   */
  6. /* size of the EA file since ... well I don't know why but */
  7. /* it consistently reports one less cluster on my system   */
  8. /* than the size of EA DATA. SF really is.                 */
  9. /* Author Trevor Hemsley - 95/04/30                        */   
  10.  
  11. Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  12. Call SysLoadFuncs
  13.  
  14. inputfile = "C:\temp\filelist.txt" /* this is the file to DIR to */
  15. outputfile = "C:\temp\ealist.txt"  /* file to contain the list   */ 
  16. file_with_ea = 0                   /* initialise counter         */  
  17. ea_amounts = 0                     /* initialise counter         */  
  18.  
  19. rx = SysFileTree("C:\TEMP",rx.,"D") /* test existence of temp dir*/
  20. if rx.0 = 0 then                          
  21.    do
  22.    say "Directory C:\TEMP does not exist. Create it Y/N?"
  23.    parse upper pull answer
  24.    if answer ¬= "Y" then exit
  25.      else 
  26.      do
  27.      "@MD C:\TEMP"
  28.      end
  29.    end
  30.  
  31. rx = stream(inputfile,"c","query exists") /* test existence of file   */
  32. if rx ¬= "" then                          /* to stop from overwriting */
  33.    do
  34.    say "Warning - existing file "inputfile" will be overwritten. Continue Y/N?"
  35.    parse upper pull answer
  36.    if answer ¬= "Y" then exit
  37.      else
  38.       "@del "inputfile
  39.    end
  40.  
  41. rx = stream(outputfile,"c","query exists") /* test existence of file */
  42. if rx ¬= "" then 
  43.    do
  44.    say "Warning - existing file "outputfile" will be overwritten. Continue Y/N?"
  45.    parse upper pull answer
  46.    if answer ¬= "Y" then exit
  47.     else
  48.      "@del "outputfile
  49.    end
  50.  
  51. do while drive_letter = "DRIVE_LETTER"       /* Ask which drive to process */
  52.   say "Which disk drive letter do you wish to examine (eg C) ?"
  53.   pull drive_letter
  54.   if length(drive_letter) = 1 then 
  55.     do 
  56.     drive_letter=drive_letter||":"
  57.     end
  58.    else
  59.     if length(drive_letter) > 2 then
  60.       do
  61.       say "Drive letter must not be more than two characters (EG C:)" 
  62.       drive_letter = "DRIVE_LETTER"
  63.       end 
  64. end
  65.  
  66. disk_info = sysdriveinfo(drive_letter)
  67. disk_size = word(disk_info,3)
  68. real_size = stream(drive_letter"\EA DATA. SF","c","Query size")
  69. if real_size = "" then 
  70.    do
  71.    say "Could not find file EA DATA. SF - this must be run against a FAT disk"
  72.    exit
  73.    end  
  74.  
  75. if disk_size > 64*1024*1024 then cluster_size=2048
  76. if disk_size > 128*1024*1024 then cluster_size=4096
  77. if disk_size > 256*1024*1024 then cluster_size=8192
  78. if disk_size > 512*1024*1024 then cluster_size=16384
  79. if disk_size > 1024*1024*1024 then cluster_size=32768
  80.  
  81. say "Total size of drive  "word(disk_info,1)" is "disk_size
  82. say "Cluster size of disk "word(disk_info,1)" is "cluster_size
  83. say "Listing file information from "word(disk_info,1)". Please wait..."
  84.  
  85. "@dir "drive_letter"\ /a /s /n >"inputfile
  86. if rc¬=0 then 
  87.   do
  88.   say "Non-zero return code ("rc") from DIR. Ending Rexx exec."
  89.   exit
  90.   end  
  91.  
  92. say "Now checking for EA's. This may take some time..."
  93.  
  94. do while lines(inputfile) ¬= 0       /* repeat for each line in input file */
  95.   rx = linein(inputfile)             /* read next record from input file   */ 
  96.   if words(rx) = 0 then iterate      /* ignore blank lines                 */
  97.   if word(rx,1) = "The" then iterate /* ignore all lines that meet the...  */
  98.   if word(rx,1) = "Directory" then iterate /* ...criteria listed here      */
  99.   if word(rx,2) = "file(s)" then iterate
  100.   if word(rx,2) = "files" then iterate
  101.   if word(rx,2) = "bytes" then iterate
  102.   if word(rx,4) = 0 then iterate
  103.      else 
  104.      do                               /* this line is for a file with EA's */
  105.      file_with_ea = file_with_ea + 1  /* add 1 to count of files found     */
  106.      ry = LINEOUT(outputfile,rx)      /* write this line to output file    */
  107.      ea_amount=word(rx,4)             /* extract size of EA's for this file*/  
  108.      if ea_amount//cluster_size = 0 then /* determine how many...          */
  109.        this_file_ea=(ea_amount%cluster_size) /* clusters the EA's take up  */
  110.       else
  111.        this_file_ea=(ea_amount%cluster_size)+1 /* round up cluster numbers */
  112.       ea_amounts=ea_amounts+this_file_ea       /* keep running total       */
  113.      end                              /* end of DO word(rx,4) = 0          */
  114. end
  115.  
  116. Say " "
  117. Say "Total files with EA's found                     "file_with_ea
  118. Say "Total size of EA DATA. SF will be approximately "ea_amounts*cluster_size
  119. size_difference = real_size-(ea_amounts*cluster_size)
  120. Say " "
  121. Say "Difference between calculated size and actual size is "size_difference
  122. If size_difference/cluster_size < 2 then 
  123.    say "This is probably nothing to worry about ! (I mean it's normal)" 
  124.  else
  125.    say "You may want to run CHKDSK "drive_letter" /F against this drive to double check."
  126. z = stream(inputfile,"c",close)        /* close input file                 */
  127. z = stream(outputfile,"c",close)       /* close output file                */
  128. "@del "inputfile                       /* clean up after us                */
  129. Say "List of files with EA's is in "outputfile ". Do you wish to keep this?"
  130. parse upper pull answer
  131. if answer = "Y" | answer ="YES" then
  132.    do
  133.    Say "Sorting file into EA size order ..."
  134.    "@sort /+32 /R <"outputfile" >"inputfile 
  135.    "@del "outputfile
  136.    "@copy "inputfile" "outputfile" >nul"
  137.    "@del "inputfile 
  138.    exit
  139.    end
  140.   else "@del "outputfile