mIRC Home    About    Download    Register    News    Help

Print Thread
#78857 11/04/04 12:08 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
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,.) }
#78858 11/04/04 12:24 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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.
#78859 11/04/04 12:54 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
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,.) }
#78860 11/04/04 01:08 PM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
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
#78861 11/04/04 02:32 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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.
#78862 11/04/04 02:41 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
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,.) }
#78863 11/04/04 02:44 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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.
#78864 11/04/04 02:48 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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.
#78865 11/04/04 03:07 PM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
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
#78866 11/04/04 05:48 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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

Link Copied to Clipboard