pmsgs You have no new messages
Thu Aug 21st 2008 Welcome, Anonymous! › Log in Or Register
› Viewing Code Snippet → $fileinfo & $findfileinfo - up to 37 types of info.

Projects's information

Project Name : $fileinfo & $findfileinfo - up to 37 types of info
File Size : 31.104 kb
Author : FiberOPtics
Project Description : Returns up to 37 characteristics of any file.
For example, various information regarding any type of audio file, video file, executables, etc.
Line Numbers : Hide Lines Number

  1. ;
  2. ; Author:      FiberOPtics -- mirc.fiberoptics@gmail.com
  3. ;
  4. ; Usage:        $fileinfo(filepath, properties [,separator])[.raw]
  5. ;
  6. ; Purpose:      Returns up to 37 characteristics of any file. For example version information
  7. ;              of .exe files, audio information of .wma/.mp3 files, etc. This uses Windows
  8. ;              to retrieve the properties, which are the same when you right click a column label
  9. ;              in Windows Explorer to specify which attributes from a file you want to see as default.
  10. ;
  11. ;
  12. ; Properties:  Audio/video:  Title Artist Author AlbumTitle Year TrackNumber Genre Duration
  13. ;                            BitRate Audiosamplesize Audiosamplerate Channels Protected Copyright
  14. ;                            EpisodeName Comments
  15. ;              Pictures:    CameraModel DatePictureTaken Dimensions
  16. ;              Executables:  ProgramDescription Company Description FileVersion ProductName ProductVersion
  17. ;              Misc:        Attributes Status Owner Subject Category Pages
  18. ;              Common:      Name Size Type DateModified DateCreated DateAccessed
  19. ;
  20. ;
  21. ; Extras:    * $findfileinfo(initialize, <properties> [, seperator])[.raw]
  22. ;              $findfileinfo(<filepath>)
  23. ;              $findfileinfo(quit)
  24. ;              
  25. ;              Findfileinfo is specifically designed to be used when you want to retrieve properties
  26. ;              about files from a large collection. For example if you want to retrieve audio properties
  27. ;              from your audio folder, which may contain hundreds or thousands of files, then $findfileinfo
  28. ;              will be better suited than fileinfo.
  29. ;
  30. ;              You first initialize findfileinfo by specifying as first parameter the word "initialize"
  31. ;              and as second parameter the properties that you will retrieve from each file in the collection.
  32. ;              Once you are done with retrieving the info, you can use "initialize" again to set new properties
  33. ;              or you can quit by specifying the keyword "quit". Let's illustrate with an example:
  34. ;
  35. ;              $findfileinfo(initialize, Artist Title Genre Duration Bitrate Audiosamplerate)
  36. ;              !.echo -q $findfile(d:\my audio\,*,0,aline @info $findfileinfo($1-))
  37. ;              $findfileinfo(quit)
  38. ;         
  39. ;
  40. ;            * /listtags
  41. ;
  42. ;            -  This alias will list all available properties that you can use on your system.
  43. ;            -  These properties will be in the language of your OS, but you must always use the
  44. ;              English properties listed above.
  45. ;
  46. ;
  47. ; Info:        - Empty values for categories are filled with a zero.
  48. ;
  49. ;              - If you specify a third parameter, this will be used as a separator between
  50. ;                the attributes. The default is a line feed $lf, which you can parse with
  51. ;                $gettok(...,N,10) or //tokenize 10 $fileinfo(...)
  52. ;
  53. ;              - There are two ways of outputting the result.
  54. ;
  55. ;                (1) Default : "Propertyname: value<separator> ..."
  56. ;                (2) Raw    : "value<seperator> ..."
  57. ;
  58. ;                The .raw property was added to give scripters more freedom in deciding the format of output.
  59. ;
  60. ;
  61. ; Installment:  The snippets go into the remote section because of their alias prefix.
  62. ;                Alt+r -> tab "Remote" -> Paste there.
  63. ;                You can also put it in the aliases section, provided you remove the alias prefix.
  64. ;
  65. ; Requirements:  $fileinfo and $findfileinfo: mIRC 5.91, Windows ME or higher
  66. ;                /listtags:  mIRC 6.14, all OS'es
  67. ;
  68. ; Notes:      - The info on executables is only available on XP+SP2. As for the rest, most of them
  69. ;                should be available on the OS'es specified in the requirements.
  70. ;
  71. ;              - Improperly tagged files, will obviously return improper info. Meaning if e.g. the
  72. ;                albumtitle attribute wasn't filled in the audiofile, then the snippet will not be able to
  73. ;                retrieve it evidently.
  74. ;
  75. ;              - After the code for the three aliases ($fileinfo, $findfileinfo, listtags) you will
  76. ;                find the same aliases but now with extensive commenting, for anyone interested in
  77. ;                seeing how the code works, and to get a better grasp on how to deal with COM and
  78. ;                VBscript from within mIRC. I've also added small explanations here and there for
  79. ;                certain coding techniques throughout the code.            
  80. ;
  81. ; Examples:      $fileinfo(d:\audio\song.wma,Artist Title Genre Duration Bitrate Audiosamplerate,**)
  82. ;                $fileinfo($mircexe,Company Productname Productversion Fileversion Type Name)
  83. ;                $fileinfo(c:\pics\mypic.jpg,Dimensions Datepicturetaken,-=-).raw
  84. ;

  85. alias fileinfo {
  86.   var %r = return $+($chr(3),$color(info),$,fileinfo:), %result
  87.   if (!$isid) %r
  88.   if ($version < 5.91) %r This snippet requires atleast mIRC 5.91.
  89.   if ($os isin 9598) %r This snippet can only work on Windows ME or higher.
  90.   if (* !iswm $2) %r You didn't specify a property to retrieve.
  91.   if (!$isfile($1)) %r File doesn't exist: $1
  92.   var %mss = mss $+ $ticks, %t, %n = $crlf, %list, %sep = $iif($len($3)," $+ $3",vblf), %file = $1
  93.   var %props = $&
  94.     Name Size Type DateModified DateCreated DateAccessed Attributes Status Owner Author Title $&
  95.     Subject Category Pages Comments Copyright Artist AlbumTitle Year TrackNumber Genre Duration $&
  96.     BitRate Protected CameraModel DatePictureTaken Dimensions . . EpisodeName ProgramDescription . $&
  97.     Audiosamplesize Audiosamplerate Channels Company Description FileVersion ProductName ProductVersion
  98.   tokenize 32 $2
  99.   while ($0) {
  100.     if ($1 != .) && ($findtok(%props,$1,1,32)) %list = $addtok(%list,$+(",$1 $calc($ifmatch -1),"),44)
  101.     tokenize 32 $2-
  102.   }
  103.   if (!%list) %r You didn't supply any valid properties.
  104.   .comopen %mss MSScriptControl.ScriptControl
  105.   if ($comerr) %r Error opening ScriptControl object.
  106.   %t = $com(%mss,language,4,bstr*,vbscript)
  107.   %t = $&
  108.     dim list, tmp, prop, res %n $&
  109.     list = array( %list ) %n $&
  110.     set shell = createobject("shell.application") %n $&
  111.     set folder = shell.namespace( $+(",$iif($nofile(%file) != $null,$ifmatch,$mircdir),") ) %n $&  
  112.     set item = folder.parsename( $+(",$nopath(%file),") ) %n $&
  113.     for each param in list %n $&
  114.     tmp = split(param," ") %n $&
  115.     prop = folder.getdetailsof(item,tmp(1)) %n $&
  116.     if len(prop) = 0 then prop = 0 %n $&  
  117.     $iif($prop != raw,prop = tmp(0) & ": " & prop) %n $&
  118.     res = res & prop & %sep %n $&
  119.     next %n $&
  120.     set item = nothing : set folder = nothing : set shell = nothing %n $&  
  121.     res = left(res,len(res)-len( %sep ))
  122.   if ($com(%mss,executestatement,1,bstr*,%t)) && ($com(%mss,eval,3,bstr*,res)) {
  123.     %result = $com(%mss).result
  124.   }
  125.   else %result = Error executing VBScript to retrieve fileinfo.
  126.   :error
  127.   if ($com(%mss)) .comclose %mss $com(%mss,reset,1)
  128.   return %result
  129. }

  130. ;
  131. ; Use this alias if you want to use fileinfo on a large collection of files at once when
  132. ; used with $findfile on an entire folder and subfolders
  133. ;
  134. ; First initialize with: $findfileinfo(initialize, <properties>)
  135. ; Call it with:          $findfileinfo(<filepath>)
  136. ; Free resources with:  $findfileinfo(quit)
  137. ;

  138. alias findfileinfo {
  139.   if (!$isid) return
  140.   var %t, %obj = findfileinfo
  141.   if ($1 == initialize) {
  142.     var %r = return $+($chr(3),$color(info),$,%obj:)
  143.     if ($version < 5.91) %r This snippet requires atleast mIRC 5.91.
  144.     if ($os isin 9598) %r This snippet can only work on Windows ME or higher.
  145.     if (* !iswm $2) %r you must specify properties to retrieve.
  146.     if ($com(%obj)) .comclose %obj
  147.     .comopen %obj MSScriptControl.ScriptControl
  148.     var %sep = $iif($len($3)," $+ $3",vblf), %n = $crlf, %list
  149.     var %props = $&
  150.       Name Size Type DateModified DateCreated DateAccessed Attributes Status Owner Author Title $&
  151.       Subject Category Pages Comments Copyright Artist AlbumTitle Year TrackNumber Genre Duration $&
  152.       BitRate Protected CameraModel DatePictureTaken Dimensions . . EpisodeName ProgramDescription . $&
  153.       Audiosamplesize Audiosamplerate Channels Company Description FileVersion ProductName ProductVersion
  154.     tokenize 32 $2
  155.     while ($0) {
  156.       if ($1 != .) && ($findtok(%props,$1,1,32)) %list = $addtok(%list,$+(",$1 $calc($ifmatch -1),"),44)   
  157.       tokenize 32 $2-
  158.     }
  159.     if (!%list) %r you didn't specify any valid properties.
  160.     %t = $com(%obj,language,4,bstr*,vbscript)
  161.     %t = $&
  162.       Function FindFileInfo(dir,file) %n $&
  163.       list = array( %list ) %n $&
  164.       set shell = createobject("shell.application") %n $&
  165.       set folder = shell.namespace(dir) %n $&  
  166.       set item = folder.parsename(file) %n $&
  167.       for each param in list %n $&
  168.       tmp = split(param," ") %n $&
  169.       prop = folder.getdetailsof(item,tmp(1)) %n $&
  170.       if len(prop) = 0 then prop = 0 %n $&  
  171.       $iif($prop != raw,prop = tmp(0) & ": " & prop) %n $&
  172.       %obj = %obj & prop & %sep %n $&
  173.       next %n $&
  174.       set item = nothing : set folder = nothing : set shell = nothing %n $&
  175.       %obj = left( %obj ,len( %obj )-len( %sep )) %n $&
  176.       End Function
  177.     %t = $com(%obj,addcode,1,bstr*,%t)
  178.     return $iif(%t == 1,$true,$false)
  179.   }
  180.   elseif ($1 == quit) && ($com(%obj)) .comclose %obj $com(%obj,reset,1)
  181.   else {
  182.     if (!$com(%obj)) || (!$isfile($1)) return
  183.     %t = FindFileInfo( $+(",$nofile($1),",$chr(44),",$nopath($1),") )
  184.     %t = $com(%obj,eval,3,bstr*,%t)
  185.     return $com(%obj).result
  186.   }
  187. }

  188. alias listtags {
  189.   var %e = !echo -ac info * /listtags:
  190.   if ($version < 6.14) { %e this alias requires atleast mIRC 6.14 | return }
  191.   var %objShell = objshell $+ $ticks, %objFolder = objfolder $+ $ticks, %i = 0, %t
  192.   .comopen %objShell shell.application
  193.   if ($comerr) { %e error opening Shell.Application object | return }
  194.   %t = $com(%objShell,namespace,1,bstr,$mircdir,dispatch* %objFolder)
  195.   if ($com(%objFolder)) {
  196.     !echo -ac info * Listing available properties on your system...
  197.     while (%i < 40) {
  198.       %t = $com(%objFolder,getdetailsof,1,bstr*,null,uint,%i)
  199.       !echo -a Index %i - $com(%objFolder).result
  200.       inc %i
  201.     }
  202.     .comclose %objFolder
  203.   }
  204.   .comclose %objShell
  205. }


  206. ; This is the end of the uncommented code. What follows are the same aliases,
  207. ; but with extensive comments for those interested in knowing a bit better
  208. ; how exactly the code works the way it does.


  209. alias fileinfo {
  210.   var %r = return $+($chr(3),$color(info),$,fileinfo:), %result

  211.   ; Basic error checking, the reason is explained in the error message that is returned.

  212.   if (!$isid) %r
  213.   if ($version < 5.91) %r This snippet requires atleast mIRC 5.91.
  214.   if ($os isin 9598) %r This snippet can only work on Windows ME or higher.
  215.   if (!$isfile($1)) %r File doesn't exist: $1
  216.   if (* !iswm $2) %r You didn't specify a property to retrieve.

  217.   ; Setting some variables, taking advantage of /var's ability to assign multiple variables on a single line.
  218.   ; The variable %mss will be used as the name of our main COM objet. We use the identifier $ticks in it
  219.   ; to make sure that the name is unique, and thus doesn't collide with another object with the same name.

  220.   var %mss = mss $+ $ticks, %t, %n = $crlf, %list, %sep = $iif($len($3)," $+ $3",vblf), %file = $1

  221.   ; We put the properties in a variable and we will later on use the position of the property
  222.   ; as an index that we need to pass to a COM object. The reason for the dots here and there,
  223.   ; is so that the properties would maintain their correct position, because Windows apparently
  224.   ; skipped a few numbers in their indexes for whatever reason. You can actually see this when
  225.   ; using the /listtags alias, which will show there are some gaps. $& is an identifier in mIRC
  226.   ; which allows you to split code on multiple lines. When mIRC evaluates it though, it puts back
  227.   ; all strings on one line, so the variable %props is one long line of properties.

  228.   var %props = $&
  229.     Name Size Type DateModified DateCreated DateAccessed Attributes Status Owner Author Title $&
  230.     Subject Category Pages Comments Copyright Artist AlbumTitle Year TrackNumber Genre Duration $&
  231.     BitRate Protected CameraModel DatePictureTaken Dimensions . . EpisodeName ProgramDescription . $&
  232.     Audiosamplesize Audiosamplerate Channels Company Description FileVersion ProductName ProductVersion

  233.   ; Tokenizing parameter $2 from the identifier, which holds the list of properties for which you
  234.   ; want to retrieve info. The looping is done using a while loop with the condition ($0), which
  235.   ; will keep looping until there are no more tokens left.

  236.   tokenize 32 $2
  237.   while ($0) {

  238.     ; If we find the specified property in the list of properties %props,
  239.     ; then add the name of the property ($1) as well as its index ($ifmatch - 1) to a
  240.     ; comma seperated variable %list which will look like: "name 0","size 1","type 2" etc.
  241.     ; The if check for $1 not being a dot is necessary, because there are dots in the variable
  242.     ; %props used to maintain the correct position of certain properties, however obviously
  243.     ; we don't want them included in our list.

  244.     if ($1 != .) && ($findtok(%props,$1,1,32)) %list = $addtok(%list,$+(",$1 $calc($ifmatch -1),"),44)

  245.     ; Tokenize all other tokens except the first one so that the second token in the list
  246.     ; now becomes the first token $1

  247.     tokenize 32 $2-
  248.   }
  249.   if (!%list) %r You didn't supply any valid properties.

  250.   ; Open the MSScriptControl.ScriptControl object which is a script interpreter, able to
  251.   ; interpret both VBscript or Jscript, thus giving us the functionality of those languages from
  252.   ; within mIRC. The name of the object is assigned to the value of variable %mss.

  253.   .comopen %mss MSScriptControl.ScriptControl

  254.   ; If there was an error opening the object, then we must stop the alias.
  255.   if ($comerr) %r Error opening ScriptControl object.

  256.   ; Set the language of the script interpreter to vbscript. Setting a property requires number 4
  257.   ; as third parameter in a $com call, and what we are passing is a basic string (bstr) by reference (*)

  258.   %t = $com(%mss,language,4,bstr*,vbscript)

  259.   ; We now populate the variable %t with the code that will do the actual retrieving of the info.
  260.   ; This code is in Visualbasicscript, and each line of code is seperated by a $crlf, which is a
  261.   ; combination of a carriage return ($cr) and a line feed ($lf).
  262.   ; We use the $& identifier in mIRC to be able to put our code on multiple lines, but when mIRC
  263.   ; will interpret it, it will put all the lines on one single line and treat them as such.
  264.   ; I cannot comment in between this lines because of the $& identifier, so I will write a summary
  265.   ; of it here instead.

  266.   ; dim list, tmp, prop, res
  267.   ; --> initializing of variables like you would do with /var

  268.   ; list = array( %list )
  269.   ; -> create an array "list" that will hold our properties from the variable %list. We cannot put
  270.   ;    array(%list) because mIRC wouldn't be able to evaluate the %list identifier. mIRC doesn't
  271.   ;    understand VBScript, so as far as it is concerned it just sees a basic string with no
  272.   ;    meaning in mIRC Scripting.

  273.   ; set shell = createobject("shell.application")
  274.   ; -> create the main object that will retrieve the info

  275.   ;  set folder = shell.namespace( $+(",$iif($nofile(%file) != $null,$ifmatch,$mircdir),") )
  276.   ; -> retrieve a reference to the folder where the file resides of which we want to find the info.
  277.   ;    We call this object "folder". $nofile(<path>) returns the path of a file without the filename.
  278.   ;    If the file didn't have a path, then it means it's a file from our main mIRC folder.
  279.   ;    The reason I use $nofile($1) != $null and not just $iif($nofile($1), ..., ...) is because
  280.   ;    a folder can be the digit "0", which would evaluate to $false in the if check. Other ways
  281.   ;    would be to use $len($nofile($1)) or * iswm, to see if $nofile($1) evaluates to
  282.   ;    something, but I choose for the != $null check so that $ifmatch can be used.

  283.   ; set item = folder.parsename( $+(",$nopath(%file),") )
  284.   ; -> retrieve a reference to the file by using $nopath which returns the filename of a filepath
  285.   ;    without the folderpath. This item in other words, is a reference to the actual file of
  286.   ;    which we will retrieve information. Note that in both this and the above case, the " "
  287.   ;    are used to represent string literals in VBscript, they are not related to the " " that you
  288.   ;    would use around a filepath in mIRC to correctly interpret spaces.

  289.   ; for each param in list
  290.   ; -> initializing a for each loop, which will loop through each property that we had stored
  291.   ;    earlier in our array "list". the variable "param" will each time be a <name>:<index> pair.

  292.   ; tmp = split(param," ")
  293.   ; -> split this parameter up into the name and the index and store it in array tmp, which we can then
  294.   ;    access with tmp(1) being the index number, and tmp(2) being the name of the property.

  295.   ; prop = folder.getdetailsof(item,tmp(1))
  296.   ; -> assign the value of the property that we access with tmp(1) and store it in variable prop.
  297.   ;    We now have retrieved the value that we were looking for.

  298.   ; if len(prop) = 0 then prop = 0
  299.   ; -> if the value of the property was empty, we will replace it with a 0.

  300.   ; $iif($prop != raw,prop = tmp(0) & ": " & prop)
  301.   ; -> If the user specified the .raw property, we will not include the name of the property in our
  302.   ;    final result. If they didn't specify it, we include it by assigning tmp(0) to variable prop.

  303.   ; res = res & prop & %sep
  304.   ; -> we store the value of variable prop into variable res, which is what we will return to mIRC
  305.   ;    once we have looped through all parameters.

  306.   ; next
  307.   ; -> this tells VBscript to continue with the loop from the top again, thus going to the next parameter.

  308.   ; set item = nothing : set folder = nothing : set shell = nothing
  309.   ; -> we release resources by setting the open COM objects to nothing. Unfortunately, the Scriptcontrol
  310.   ;    object doesn't seem to want to perform this properly, but I added it anyway because it's more "correct".
  311.   ;   

  312.   ; res = left(res,len(res)-len( %sep ))
  313.   ; -> we are done with looping, and now have the variable res with all our information we requested
  314.   ;    This variable's value will now be retrieved back with regular mIRC scripting.

  315.   %t = $&
  316.     dim list, tmp, prop, res %n $&
  317.     list = array( %list ) %n $&
  318.     set shell = createobject("shell.application") %n $&
  319.     set folder = shell.namespace( $+(",$iif($nofile(%file) != $null,$ifmatch,$mircdir),") ) %n $&  
  320.     set item = folder.parsename( $+(",$nopath(%file),") ) %n $&
  321.     for each param in list %n $&
  322.     tmp = split(param," ") %n $&  
  323.     prop = folder.getdetailsof(item,tmp(1)) %n $&
  324.     if len(prop) = 0 then prop = 0 %n $&  
  325.     $iif($prop != raw,prop = tmp(0) & ": " & prop) %n $&
  326.     res = res & prop & %sep %n $&
  327.     next %n $&
  328.     set item = nothing : set folder = nothing : set shell = nothing %n $&
  329.     res = left(res,len(res) - len( %sep ))

  330.   ; The following if check does two things:

  331.   ; 1) It evaluates two times a $com call, first time with method "executestatement" which will execute
  332.   ;    the code that we had filled our variable %t with. Therefore we pass this variable %t as an argument
  333.   ;    to the $com call. Secondly, it evaluates another $com call by calling the "eval" property on the COM
  334.   ;    object. That will make the code that we just executed evaluated, and allows us to retrieve the value
  335.   ;    of the VBscript variable "result". Therefore we pass this variable as a bstr* to the $com call.

  336.   ; 2) It checks to see if both $com calls were successfully. If they were, they both returned "1",
  337.   ;    which makes the code proceed to the statement: %result = $com(%mss).result
  338.   ;    If they weren't successful, then it goes to the statement: %r Error executing VBScript to
  339.   ;    retrieve fileinfo.
  340.   ;    Don't confuse the .result property of $com() with our VBscript variable "result".
  341.   ;    They have nothing to do with each other. $com(<object>) result will always store the result
  342.   ;    of property call on an object in mIRC. It's simply a coincidence that I used the name "result"
  343.   ;    to store the properties in VBscript.

  344.   if ($com(%mss,executestatement,1,bstr*,%t)) && ($com(%mss,eval,3,bstr*,result)) {
  345.     %result = $com(%mss).result
  346.   }
  347.   else %result = Error executing VBScript to retrieve fileinfo.

  348.   ; This error label will make mIRC jump to here in case any error has occured when mIRC was interpreting
  349.   ; the code. In here, we close the com object if it was still open, but first resetting it to free any
  350.   ; resources used in the VBScript code such as our open objects. We use this method additinoally to adding
  351.   : something like: set shell = nothing. Normally this works in VBScript, but the Script Interpreter
  352.   : doesn't perform it properly, therefore the reset method.

  353.   :error
  354.   if ($com(%mss)) .comclose %mss $com(%mss,reset,1)

  355.   ; We return our result which was stored earlier in variable %result if no error has happened.
  356.   ; If an error has happened, %result will just be empty, so it will return nothing. That's why
  357.   ; we intialized %result at the beginning of the code. If an error would happen before %result
  358.   ; is initialized as a local variable, then it would return the value of a possibly existing
  359.   ; global variable %result, something we definitely don't want.

  360.   return %result
  361. }


  362. ; Use this alias if you want to use fileinfo on a large collection of files at once when
  363. ; used with $findfile on an entire folder and subfolders
  364. ;
  365. ; First initialize with: $findfileinfo(initialize,<properties>)
  366. ; Call it with:          $findfileinfo(<filepath>)
  367. ; Free resources with:  $findfileinfo(quit)
  368. ;

  369. alias findfileinfo {

  370.   ; Commenting for this snippet will be less than for $fileinfo, because a lot of the code is the same.
  371.   ; I will only explain the differences, and why exactly I made it different.

  372.   ; If the alias was called as command instead of an identifier, then return.
  373.   if (!$isid) return

  374.   ; Instead of using a unique variable like in $fileinfo, we specify as name "findfileinfo", because
  375.   ; this object must remain open in your mIRC until you decide to manually close it with $findfileinfo(quit)

  376.   var %t, %obj = findfileinfo

  377.   if ($1 == initialize) {

  378.     ; Very similar code as for $fileinfo until the VBscript code.

  379.     var %r = return $+($chr(3),$color(info),$,findfileinfo:)
  380.     if ($version < 5.91) %r This snippet requires atleast mIRC 5.91.
  381.     if ($os isin 9598) %r This snippet can only work on Windows ME or higher.
  382.     if (* !iswm $2) %r you must specify properties to retrieve.
  383.     if ($com(%obj)) .comclose %obj
  384.     .comopen %obj MSScriptControl.ScriptControl
  385.     var %sep = $iif($len($3)," $+ $3",vblf), %n = $crlf, %list
  386.     var %props = $&
  387.       Name Size Type DateModified DateCreated DateAccessed Attributes Status Owner Author Title $&
  388.       Subject Category Pages Comments Copyright Artist AlbumTitle Year TrackNumber Genre Duration $&
  389.       BitRate Protected CameraModel DatePictureTaken Dimensions . . EpisodeName ProgramDescription . $&
  390.       Audiosamplesize Audiosamplerate Channels Company Description FileVersion ProductName ProductVersion
  391.     tokenize 32 $2
  392.     while ($0) {
  393.       if ($1 != .) && ($findtok(%props,$1,1,32)) %list = $addtok(%list,$+(",$1 $calc($ifmatch -1),"),44)   
  394.       tokenize 32 $2-
  395.     }
  396.     if (!%list) %r you didn't specify any valid properties.
  397.     %t = $com(%obj,language,4,bstr*,vbscript)

  398.     ; You will notice here that unlike in $fileinfo, the VBScript starts different.
  399.     ; Here I am creating a function in VBScript called "FindFileInfo" that takes two parameters,
  400.     ; being a path to a folder (dir) and a file name (file). At the end of the VBscript, we finish
  401.     ; the declaration of the function with the statement "End Function".
  402.     ;  
  403.     ; You also notice that instead of initializing variable "res" I am now intializing the variable
  404.     ; "findfileinfo". This variable will be used to return our result. In VBscript, when you call a
  405.     ; function that is supposed to return a result, you will put the value of this result in the
  406.     ; variable that has the same name as the function. For example:
  407.     ;
  408.     ; Function MyFunc()
  409.     ;    myfunc = "woot"
  410.     ; End Function
  411.     ; When calling The MyFunc() function, it will return the value of myfunc, being the string woot.
  412.     ;

  413.     %t = $&
  414.       Function FindFileInfo(dir,file) %n $&
  415.       dim list, tmp, prop, %obj %n $&
  416.       list = array( %list ) %n $&
  417.       set shell = createobject("shell.application") %n $&
  418.       set folder = shell.namespace(dir) %n $&  
  419.       set item = folder.parsename(file) %n $&
  420.       for each param in list %n $&
  421.       tmp = split(param," ") %n $&
  422.       prop = folder.getdetailsof(item,tmp(1)) %n $&
  423.       if len(prop) = 0 then prop = 0 %n $&  
  424.       $iif($prop != raw,prop = tmp(0) & ": " & prop) %n $&
  425.       %obj = %obj & prop & %sep %n $&
  426.       next %n $&
  427.       set item = nothing : set folder = nothing : set shell = nothing %n $&
  428.       %obj = left( %obj ,len( %obj )-len( %sep )) %n $&
  429.       End Function

  430.     ; Instead of doing "executestatement" and "eval" like in $fileinfo, all we do is add this FindFileInfo
  431.     ; function to the Script interpreter without making it do anything. For this we use the "addcode" method.
  432.     ; We do this because with future calls of FindFileInfo, we only then need to do a simple "eval" to get our
  433.     ; required results. The main difference here is that the properties to retrieve have been hardcoded in the
  434.     ; VBScript function. With each call of $findfileinfo it will retrieve the same properties, only the file
  435.     ; will be different.

  436.     %t = $com(%obj,addcode,1,bstr*,%t)
  437.     ; %t will store the value of our $com call. If it was successful1 (1) return $true, else return $false.
  438.     return $iif(%t == 1,$true,$false)
  439.   }

  440.   ; If you specified $findfileinfo(quit) then we close the main object if it is open,
  441.   ; whilst calling the reset method on it. We do this to free any resources used by the
  442.   ; VBscript like the COM objects. You can see that we have the $com(%obj,reset,1) on the
  443.   ; same line as the .comclose %obj code, which may look confusing, because aren't we
  444.   ; closing the object first, so how could we still invoke a method on this object?
  445.   ; In mIRC, when executing a command, mIRC first evaluates any parameters passed to the
  446.   ; command. If it wouldn't, then if you did //echo -a $me, it would never show your real
  447.   ; nickname, but rather echo $me. Instead mIRC evaluates $me to your current nickname,
  448.   ; and then it echoes it. Similarly here, mIRC first evaluates the $com identifier,
  449.   ; before it closes the object.
  450.   ;

  451.   elseif ($1 == quit) && ($com(%obj)) .comclose %obj $com(%obj,reset,1)
  452.   else {

  453.     ; If you didn't specify a valid filepath, or if the main object doesn't exist, then return.
  454.     if (!$com(%obj)) || (!$isfile($1)) return

  455.     ; First assign the string FindFileinfo("<folderpath>","<filename>") to variable %t.
  456.     %t = FindFileInfo( $+(",$nofile($1),",$chr(44),",$nopath($1),") )