mIRC Homepage
Posted By: westor $folder identifier - 14/08/14 10:26 AM
Hello,

I wonder if the $folder identifier can be added on the mIRC that will return some useful output results with some props too, like $file identifier.

Props: .size - .mtime - .longfn - .shortfn - .attr

e.g: $folder($mircdir).size
output: 1334784

e.g2: $folder($mircdir).mtime
output: 1403816309

e.g3: $folder($mircdir).longfn
output: C:\Users\Dimitris\Documents\mIRC\

e.g4: $folder($mircdir).shortfn
output: C:\Users\Dimitris\DOCUME~1\mIRC\

e.g5: $folder($mircdir).attr
output: ar

- Thanks!
Posted By: Loki12583 Re: $folder identifier - 14/08/14 11:32 AM
$file already does all those things for directories except for size
Posted By: FroggieDaFrog Re: $folder identifier - 14/08/14 11:56 AM
As loki said $file() can already do everything you've asked except the size property

With a little help from COM we can mimic all of $file()'s behavior. The follow alias maps everything but the .size property to $file()

If the .size property is specified, it opens a com to the FileSystemObject, retrieves the folder properties, then returns the size property value

Code:
alias folder {
  var %com = folder, %com2 = prop, %err, %res
  if ($prop != size) return $file($1-) [ $+ [ $iif($prop,. $+ $prop) ] ]
  if ($isdir($1-)) {
    .comopen %com Scripting.FileSystemObject
    if ($com(%com) && !$comerr) && ($com(%com, GetFolder, 1, bstr, $noqt($1-), dispatch* %com2) && !$comerr) && ($com(%com2, size, 2) && !$comerr) {
      %res = $com(%com2).result
    }
  }
  :error
  reseterror
  if ($com(%com)) { .comclose $v1 }
  if ($com(%com2)) { .comclose $v1 }
  return %res
}




Now, with that out of the way, I think $file() should be extended to handle folder sizes aswell

;edited:
Fixed typo in script
Posted By: westor Re: $folder identifier - 14/08/14 01:52 PM
The code does NOT working, also i didn't knew that the $file working for folders, thanks, but the problem is that $file($mircdir).size (for example) does NOT work, so the suggestion is to make the $file(dir).size to work for folders size.
Posted By: FroggieDaFrog Re: $folder identifier - 14/08/14 02:16 PM
There was a typing mistake in the script. It is fixed
Posted By: westor Re: $folder identifier - 14/08/14 03:52 PM
Thanks for the code, but i am still say to this must be added in $file(FOLDER).size identifier!

- Thanks!
Posted By: starbucks_mafia Re: $folder identifier - 14/08/14 08:18 PM
If by folder size you mean the total size of its contents then just loop through its contents with $findfile() & $file().size and add it up yourself - that's effectively what mIRC would have to do behind the scenes anyway.

It's perhaps best not implemented as a built-in identifier as it can be slow to calculate if the directory contains many (ie. thousands) of files. Generally speaking people assume mIRC's built-in identifiers will return a value near-instantaneously.
Posted By: hixxy Re: $folder identifier - 14/08/14 09:09 PM
Code:
alias folder { 
  if (!$isdir($1-)) { return }
  if ($prop == size) { 
    var %size 
    noop $findfile($1-,*,0,inc %size $file($1-).size)
    return %size
  }
  return $file($1-) [ $+ [ $iif($prop,. $+ $v1) ] ]
}


Edit: don't use that on a big folder :p Took 5 minutes to calculate the size of my Windows directory!
Posted By: FroggieDaFrog Re: $folder identifier - 15/08/14 04:52 AM
Without DLLs or the property being built in, I think my code above is the fastest way to get total size.

I do think the .size prop should be updated to calculate folder size aswell. From my com example above, windows already abstracts the calculations for programmers so extending it should not only be easy, but probably quite a bit more efficient compared to programmatic looping within mIRC
Posted By: westor Re: $folder identifier - 15/08/14 01:21 PM
I agree with FroggieDaFrog , The loop way it was the first one but i think this would not be a good method for large folders the option to add something new in mIRC and useful is the best. so if Khaled add support for $file(FOLDER).size so it could be the best and fastest.
© mIRC Discussion Forums