mIRC Home    About    Download    Register    News    Help

Print Thread
$folder identifier #247593 14/08/14 10:26 AM
Joined: Dec 2008
Posts: 1,511
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
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!

Re: $folder identifier [Re: westor] #247594 14/08/14 11:32 AM
Joined: Jan 2004
Posts: 1,277
L
Loki12583 Online
Hoopy frood
Online
Hoopy frood
L
Joined: Jan 2004
Posts: 1,277
$file already does all those things for directories except for size

Re: $folder identifier [Re: westor] #247596 14/08/14 11:56 AM
Joined: Apr 2010
Posts: 924
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 924
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

Last edited by FroggieDaFrog; 14/08/14 02:16 PM.

I am SReject
My Stuff
Re: $folder identifier [Re: FroggieDaFrog] #247597 14/08/14 01:52 PM
Joined: Dec 2008
Posts: 1,511
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
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.

Re: $folder identifier [Re: westor] #247598 14/08/14 02:16 PM
Joined: Apr 2010
Posts: 924
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 924
There was a typing mistake in the script. It is fixed


I am SReject
My Stuff
Re: $folder identifier [Re: FroggieDaFrog] #247601 14/08/14 03:52 PM
Joined: Dec 2008
Posts: 1,511
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
Thanks for the code, but i am still say to this must be added in $file(FOLDER).size identifier!

- Thanks!

Re: $folder identifier [Re: westor] #247606 14/08/14 08:18 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: $folder identifier [Re: westor] #247609 14/08/14 09:09 PM
Joined: Sep 2005
Posts: 2,878
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,878
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!

Last edited by hixxy; 14/08/14 09:15 PM.
Re: $folder identifier [Re: westor] #247612 15/08/14 04:52 AM
Joined: Apr 2010
Posts: 924
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 924
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


I am SReject
My Stuff
Re: $folder identifier [Re: FroggieDaFrog] #247619 15/08/14 01:21 PM
Joined: Dec 2008
Posts: 1,511
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
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.