mIRC Home    About    Download    Register    News    Help

Print Thread
#137660 17/12/05 06:04 AM
Joined: Jul 2004
Posts: 59
S
synth7 Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Jul 2004
Posts: 59
Code:
alias biggestfile {
  var %i = 0, %size = 0, %b = $findfile($1-,*,0), %s
  while (%b > %i) {
    %s = $bytes($file($findfile($1-,*,%b)).size,k3)
    if (%s > %size) {
      %size = $bytes($file($findfile($1-,*,%b)).size,k3)
      dec %b
    }
  }
  return %size
}


What it's *supposed* to do is find the filesize of the largest file in whatever directory. Usage of the identifer is $biggestfile(c:\foldname\here). However, the only times I've tried to use it, it has (apparently) been processing all the loops or something, and I end up having to close mIRC by killing the process. Did I leave out a vital part of the code, or something like that?

Thanks.



Joined: Jul 2004
Posts: 59
S
synth7 Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Jul 2004
Posts: 59
I made it work.

Code:
alias biggestfile {
  var %Count = 0, %LargestFileSize = 0, %FilesInFolder = $findfile($1-,*,0), %SubdirsInFolder = $finddir($1-,*,0), %TempSizeBuffer, %LargestFileName
  while (%FilesInFolder > %Count) {
    inc %Count
    %TempSizeBuffer  = $file($findfile($1-,*,%Count)).size
    if (%TempSizeBuffer > %LargestFileSize) {
      %LargestFileSize = %TempSizeBuffer
      %LargestFileName = $nopath($findfile($1-,*,%Count))
    }
  }
  return %LargestFileName ( $+ $bytes(%LargestFileSize,k3).suf $+ )
}


I'd still appreciate comments on my "final" version, if anything can be done better, etc.



Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
This should be much much faster as it uses $findfiles internal looping ability.

Code:
alias biggestfile {
  set -u %largefile
  set -u %largefilesize 0
  !.echo -q $findfile($1,*.*,0,checkfile $1-)
  return $iif($prop == size,$bytes(%largefilesize,k3),%largefile)
}
alias checkfile {
  if ($file($1-) > %largefilesize) {
    %largefile = $1-
    %largefilesize = $v1
  }
}


$biggestfile(dir) returns the name of the largest file, $biggestfile(dir).size returns the size of the largest file.


Link Copied to Clipboard