mIRC Home    About    Download    Register    News    Help

Topic Options
#78857 - 11/04/04 01:08 PM $calc
sparta Offline
Planetary brain

Registered: 22/02/03
Posts: 3432
Loc: Sweden/Borlänge
How would you easyest calc the size of a folder ? like if i want to calc the size of mirc folder when i start mirc ?
_________________________
if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }

Top
#78858 - 11/04/04 01:24 PM Re: $calc
starbucks_mafia Offline
Hoopy frood

Registered: 09/12/02
Posts: 2962
Loc: Norwich, UK
Code:
var %size = 0
!.echo -q $findfile($mircdir, *, 0, inc %size $file($1-))
[color:red]; %size now contains the dir size[/color]

Of course depending on the size of your mIRC directory it could take several seconds to process.
_________________________
Spelling mistakes, grammatical errors, and stupid comments are intentional.

Top
#78859 - 11/04/04 01:54 PM Re: $calc
sparta Offline
Planetary brain

Registered: 22/02/03
Posts: 3432
Loc: Sweden/Borlänge
that didnt work, it give me the number "21" .. but the size is 2.5 meg ..it's 21 files in the folder tho..
_________________________
if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }

Top
#78860 - 11/04/04 02:08 PM Re: $calc
tidy_trax Offline
Hoopy frood

Registered: 02/11/03
Posts: 2327
Code:
alias folder {
  var %x
  if $prop == size { .echo -q $findfile($1,*.*,0,inc %x $file($1-)) }
  elseif $prop == files { .echo -q $findfile($1,*.*,0,var %x = %x $nopath($1-) $+ $chr(44) $+ $chr(32)) }
  elseif $prop == filecount { var %x = $findfile($1,*.*,0) }
  elseif $prop == folder { .echo -q $finddir($1,*,0,var %x = %x $gettok($1-,-1,$asc(\)) $+ $chr(44) $+ $chr(32)) }
  elseif $prop == foldercount { var %x = $finddir($1,*,0) }
  elseif !$prop || $prop == isdir { var %x = $isdir($1) }
  if $right(%x,1) == $chr(44) { %x = $left(%x,-1) }
  return %x
}


small snippet i made

$folder(folder)[.size|.files|.filecount|.folders|.foldercount|.isdir]

.size will return the size of the folder
.files will return the files in the folder
.filecount will return the amount of files in the folder
.folders will return the folders in the folder
.foldercount will return the amount of folders in the folder
.isdir or no property will return if the directory exists or not
_________________________
New username: hixxy

Top
#78861 - 11/04/04 03:32 PM Re: $calc
starbucks_mafia Offline
Hoopy frood

Registered: 09/12/02
Posts: 2962
Loc: Norwich, UK
The code I gave you works - %size contains the size of the folder, I'm guessing you edited it and used $findfile() as the value (which is incorrect).
_________________________
Spelling mistakes, grammatical errors, and stupid comments are intentional.

Top
#78862 - 11/04/04 03:41 PM Re: $calc
sparta Offline
Planetary brain

Registered: 22/02/03
Posts: 3432
Loc: Sweden/Borlänge
i didnt tutch it.. copyed it in to remote, then tryed it.. and it gave me then answer 21, and thats how many files i have in that folder, not how big it is
_________________________
if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }

Top
#78863 - 11/04/04 03:44 PM Re: $calc
starbucks_mafia Offline
Hoopy frood

Registered: 09/12/02
Posts: 2962
Loc: Norwich, UK
There's some problems with that code:

- You should use * instead of *.* for $findfile() matching - a filename doesn't always contain a period.
- Since you've already declared %x as local there's no need to re-use /var - it's much slower than the %var = value syntax in my experience.
- You shouldn't delimit file/folder lists with commas - both can contain commas themselves.
- %x = %x $gettok($1-,-1,$asc(\)) $+ $chr(44) $+ $chr(32) - The $+ $chr(32) is pointless.
- elseif $prop == folder - Missed the 's' in 'folders'.
_________________________
Spelling mistakes, grammatical errors, and stupid comments are intentional.

Top
#78864 - 11/04/04 03:48 PM Re: $calc
starbucks_mafia Offline
Hoopy frood

Registered: 09/12/02
Posts: 2962
Loc: Norwich, UK
Code:
alias sizetest {
  var %size = 0
  !.echo -q $findfile($mircdir, *, 0, inc %size $file($1-)); %size now contains the dir size
  echo -a %size
}

Put that in your remotes (Alt+R), and type /sizetest - does it echo the correct size (remember the value is in bytes).
_________________________
Spelling mistakes, grammatical errors, and stupid comments are intentional.

Top
#78865 - 11/04/04 04:07 PM Re: $calc
tidy_trax Offline
Hoopy frood

Registered: 02/11/03
Posts: 2327
i found that %x = doesn't work in $findfile(), i had to use var %x =

%x = gives: * /echo: insufficient parameters

newer code:
Code:
alias folder {
  var %x
  if $prop == size { .echo -q $findfile($1,*.*,0,inc %x $file($1-)) }
  elseif $prop == files { .echo -q $findfile($1,*.*,0,var %x = %x $nopath($1-) $+ $chr(44)) }
  elseif $prop == filecount { %x = $findfile($1,*.*,0) }
  elseif $prop == folders { .echo -q $finddir($1,*,0,var %x = %x $gettok($1-,-1,$asc(\)) $+ $chr(44)) }
  elseif $prop == foldercount { %x = $finddir($1,*,0) }
  elseif !$prop || $prop == isdir { %x = $isdir($1) }
  if $right(%x,1) == $chr(44) { %x = $left(%x,-1) }
  return %x
}
_________________________
New username: hixxy

Top
#78866 - 11/04/04 06:48 PM Re: $calc
qwerty Offline
Hoopy frood

Registered: 07/01/03
Posts: 2523
I'd also use $findfile().shortfn, which would take into account filenames that contain double spaces. That's because $1- does not retain any consecutive spaces, so $file($1-) on such files will be $null.

Here's a faster $size() alternative, using COM objects:
Code:
alias size {
  if !$isdir($1) { return }
  var %a = fso $+ $ticks, %b = getfolder $+ %a
  .comopen %a Scripting.FileSystemObject
  if $comerr { return }
  if $com(%a,GetFolder,1,bstr,$1,dispatch* %b) && $com(%b) {
    .comclose %a $com(%b,Size,2)
    %a = $com(%b).result
    .comclose %b
    return $int(%a)
  }
  .comclose %a
}
_________________________
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Top