|
Joined: Feb 2003
Posts: 3,432
Hoopy frood
|
OP
Hoopy frood
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,.) }
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,962 |
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.
|
|
|
|
Joined: Feb 2003
Posts: 3,432
Hoopy frood
|
OP
Hoopy frood
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,.) }
|
|
|
|
Joined: Nov 2003
Posts: 2,327
Hoopy frood
|
Hoopy frood
Joined: Nov 2003
Posts: 2,327 |
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
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: Feb 2003
Posts: 3,432
Hoopy frood
|
OP
Hoopy frood
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,.) }
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,962 |
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.
|
|
|
|
Joined: Nov 2003
Posts: 2,327
Hoopy frood
|
Hoopy frood
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:
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
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
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: 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
|
|
|
|
|