home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / disks / tools / afsdefrag / defrag < prev    next >
Text File  |  1996-07-22  |  2KB  |  86 lines

  1. /* Defrag file on an AFS disk */
  2. /* June 19, 1996 by Kirk Strauser */
  3.  
  4.  
  5. parse arg volume minf
  6.  
  7. if arg()=0 then do
  8.    say 'Usage: Defrag VOLUME: MINFRAGS'
  9.    exit
  10.    end
  11.  
  12. minf=strip(minf)
  13. if datatype(minf)='CHAR' then minf=2
  14.  
  15. tempdir='t:'
  16.  
  17. say 'Scanning 'volume' for files with 'minf' or more fragments...'
  18. say ' '
  19.  
  20. address command
  21. 'diskvalid '||volume||' analyse >t:temp'
  22.  
  23. if ~open(list,'t:temp','r') then do
  24.    say 'Had trouble opening the temp file.'
  25.    exit
  26.    end
  27.  
  28. a=readln(list)
  29.  
  30. if a="couldn't find device!!" then do
  31.    say "DiskValid couldn't find "volume
  32.    exit
  33.    end
  34. if a="couldn't inhibit device" then do
  35.    say "DiskValid couldn't inhibit "volume
  36.    exit
  37.    end
  38. a=readln(list);a=readln(list)
  39. if a="not an afs disk" then do
  40.    say volume' is not an AFS disk.'
  41.    exit
  42.    end
  43. if left(a,10)='read error' then do
  44.    say 'DiskValid encountered a read error on 'volume
  45.    exit
  46.    end
  47.  
  48. flag=0
  49.  
  50. do until eof(list)
  51.    a=readln(list)
  52.    parse var a o1 o2 file
  53.    if o1='fragmented' then do
  54.       file=substr(file,2)
  55.       w=words(file);w2=wordindex(file,w-1)
  56.       frag=substr(word(file,w-1),2)
  57.       file=left(file,w2-2)
  58.       l=lastpos('~',file)
  59.       if l>0 then do
  60.          file=left(file,l-1)||'*'||substr(file,l)
  61.          end
  62.       if frag>=minf then do
  63.          say 'Defragmenting: 'file' ('frag' fragments)...'
  64.          'copy "'||file||'" t:defragtempfile'
  65.          'copy t:defragtempfile "'||file||'"'
  66.          flag=flag+1
  67.          end
  68.       if frag<minf then do
  69.          say 'Skipping file: 'file' ('frag' fragments)...'
  70.          end
  71.       end
  72.    end
  73.  
  74. call close list
  75. 'delete >nil: t:temp'
  76.  
  77. if flag=0 then do
  78.    say 'No fragmented files found.'
  79.    exit
  80.    end
  81. say 'Found and defragmented 'flag' files on 'volume'.'
  82. 'delete >nil: '||tempdir||'defragtempfile'
  83. exit
  84.  
  85. $VER: AFSFileDefrag 1.1 (14.7.96)
  86.