$foldersize using COM

By FiberOPtics on Jan 04, 2006



Author: FiberOPtics -- mirc.fiberoptics@gmail.com




Usage: $foldersize(folderpath [, bkmgt3])[.suf]




Purpose: Returns the size of a folder or drive, including subfolders.




Since the snippet uses COM, it is much faster than the $findfile
equivalents out there, especially on huge folders with several
hundreds of mega/gigabytes.




You can specify a second parameter b,k,m,g,t or 3, which are the
parameters from the built-in $bytes identifier, to format the result. The default output is in bytes, without commas. You can specify the .suf property, which adds the suffix of the chosen format, like B, MB, GB etc.




Requires:


mIRC 6.14 because the dispatch bug was only fixed there


Windows 95/98/NT4.0 + Internetexplorer 4.0


Windows 2k/XP/2k3




Examples:


$foldersize(c:\program files)


$foldersize(c:\mp3,g).suf


$foldersize(d:\,g)

alias foldersize {
  var %e = return $+($chr(3),$color(info),$,foldersize:), %size
  if (!$isid) return
  if ($version < 6.14) %e this snippet requires atleast mIRC version 6.14
  if (!$isdir($$1)) %e no such folder $1
  if ($0 > 1) && (!$istok(b k m g t 3,$2,32)) %e Incorrect parameter.
  if ($prop) && ($prop != suf) %e property can only be suf, to format the number
  if ($regex(fsize,$1,/^[a-z]:[\57\134]*$/i)) %size = $disk($1).size
  else {
    var %objFso = a $+ $ticks, %objFolder = b $+ $ticks
    .comopen %objFso Scripting.FileSystemObject
    if ($comerr) %e error opening FSO object
    .comclose %objFso $com(%objFso,GetFolder,1,bstr*,$1,dispatch* %objFolder)
    if ($com(%objFolder)) {
      !.echo -q $com(%objFolder,Size,2)
      %size = $com(%objFolder).result
      .comclose %objFolder
    }
  }
  return $iif($2,$bytes(%size,$2). [ $+ [ $prop ] ],%size)
}

Comments

Sign in to comment.
FiberOPtics   -  Jan 04, 2006

Thanks, I appreciate it. This looks like a nice community btw, quite friendly people.

 Respond  
QuickStep   -  Jan 04, 2006

I gave you a high rating on the submitted scripts to balance it out a little, since I think it deservers higher.

 Respond  
QuickStep   -  Jan 04, 2006

FiberOPtics that\'s normal around here. People tend to look at \'functionality\' rather than code-wise (in your case overall very proffesional looking), meaning that if somebody who doesnt know what it does, and hence doesnt find it usefull, gives a low score.

Well thats how it nearly always goes around here. Anyway nice to see you moving over from mircscripts.org to hawkee. Good coder

 Respond  
FiberOPtics   -  Jan 04, 2006

Tried to edit my other post until I realized there\'s no edit feature.

Thanks for your comment, RoninWarrior.

 Respond  
FiberOPtics   -  Jan 04, 2006

You guys give really low scores here o.O

Is there something wrong with the code, not functioning? This is pretty unique functionality, and retrieves the size of a folder much faster than mIRC ever could with $findfile so I\'m wondering what\'s the problem?

 Respond  
RoninWarrior   -  Jan 04, 2006

nice job fiber i use the .suf with my mp3 player for returning the folder sizes of each folder etc etc and also for my fileserver im going to impliment this to it know for a change great work.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.