$fileinfo & $findfileinfo: 37 types of info

By FiberOPtics on Jan 04, 2006



Author: FiberOPtics -- mirc.fiberoptics@gmail.com




Usage:


1)




$fileinfo(filepath, properties [,separator])[.raw]




Will retrieve information about a file. The possible properties are listed further below.




2)




$findfileinfo( initialize, properties [, seperator])[.raw]


$findfileinfo()


$findfileinfo(quit)




Findfileinfo is specifically designed to be used when you want to retrieve properties about files from a large collection. For example if you want to retrieve audio properties from your audio folder, which may contain hundreds or thousands of file, then $findfileinfo will be better suited than fileinfo.




You first initialize findfileinfo by specifying as first parameter the word "initialize" and as second parameters the properties that you will retrieve from each file in the collection. Once you are done with retrieving the info, you can use "initialize" again to set new properties or you can quit by specifying the keyword "quit". Let's make an example:




$findfileinfo(initialize, Artist Title Genre Duration Bitrate Audiosamplerate)


!.echo -q $findfile(d:\my audio\,*,0,aline @info $findfileinfo($1-))


$findfileinfo(quit)




3)




/listtags




This alias will list all available properties that you can use on your system. These properties will be in the language of your OS, but you must always use the English properties that you see right under this.






Properties:




Audio/video: Title Artist Author AlbumTitle Year TrackNumber Genre Duration BitRate Audiosamplesize Audiosamplerate Channels Protected Copyright EpisodeName Comments






Pictures: CameraModel DatePictureTaken Dimensions




Executables: ProgramDescription Company Description FileVersion ProductName ProductVersio




Misc: Attributes Status Owner Subject Category Pages




Common: Name Size Type DateModified DateCreated DateAccessed






Purpose: Returns up to 37 characteristics of any file. For example version information of .exe files, audio information of .wma/.mp3 files, etc. This uses Windows to retrieve the properties, which are the same when you right click a column label in Windows Explorer to specify which attributes from a file you want to see as default.






Info:



  • Filepath must be the complete filepath, even when the file resides in the mIRC folder.



  • Empty values for categories are filled with a zero.



  • If you specify a third parameter, this will be used as a separator between the attributes. The default is a line feed $lf, which you can parse with $gettok(...,N,10) or //tokenize 10 $fileinfo(...)



  • There are two ways of outputting the result.




    (1) Default : "Propertyname: value ..."




    (2) Raw : "value ..."




    The .raw property was added to give scripters more freedom in deciding the format of output.






    Installment: The snippets go into the remote section because of their alias prefix. Alt+r -> tab "Remote" -> Paste there. You can also put it in the aliases section, provided you remove the alias prefix.




    Requirements:




    $fileinfo and $findfileinfo: mIRC 5.91, Windows ME or higher




    /listtags: mIRC 6.14, all OS'es






    Notes:




    The info on executables is only available on XP+SP2. As for the rest, most of them should be available on the OS'es specified in the requirements.






    Improperly tagged files, will obviously return improper info. Meaning if e.g. the albumtitle attribute wasn't filled in the audiofile, then the snippet will not be able to retrieve it evidently.






    Examples:




    $fileinfo(d:\audio\song.wma,Artist Title Genre Duration Bitrate Audiosamplerate,**)




    $fileinfo($mircexe,Company Productname Productversion Fileversion Type Name)




    $fileinfo(c:\pics\mypic.jpg,Dimensions Datepicturetaken,-=-).raw

alias fileinfo {
  var %e = return $+($chr(3),$color(info),$,fileinfo:), %result
  if ($version < 5.91) %e This snippet requires atleast mIRC 5.91
  if ($istok($OS,95 98,32)) %e This snippet can only work on Windows ME or higher.
  if (!$isid) %e This function can only be used as an identifier.
  if (!$isfile($1)) %e File doesn't exist: $1-
  if (* !iswm $2) %e You didn't specify a property to retrieve.
  var %id = $ticks $+ $r(1111,9999), %mss = mss $+ %id, %t, %n = $crlf
  var %file = $1, %list, %sep = $iif($len($3)," $+ $3",vblf)
  var %props = $&
    Name Size Type DateModified DateCreated DateAccessed Attributes Status Owner Author Title $&
    Subject Category Pages Comments Copyright Artist AlbumTitle Year TrackNumber Genre Duration $&
    BitRate Protected CameraModel DatePictureTaken Dimensions . . EpisodeName ProgramDescription . $&
    Audiosamplesize Audiosamplerate Channels Company Description FileVersion ProductName ProductVersion
  tokenize 32 $2
  while ($0) {
    if ($findtok(%props,$1,1,32)) %list = $addtok(%list,$+(",$1,:,$calc($ifmatch - 1),"),44)
    tokenize 32 $2-
  }
  if (!%list) %e You didn't supply any valid properties. 
  .comopen %mss MSScriptControl.ScriptControl
  if ($comerr) %e Error opening ScriptControl object.
  %t = $com(%mss,language,4,bstr*,vbscript)
  %t = $&
    list = array( %list ) %n $&
    set shell = createobject("shell.application") %n $&
    set folder = shell.namespace(" $+ $nofile(%file) $+ ") %n $&  
    set item = folder.parsename(" $+ $nopath(%file) $+ ") %n $&
    for each index in list %n $&
    tmp = split(index,":") %n $& 
    prop = folder.getdetailsof(item,tmp(1)) %n $& 
    if len(prop) = 0 then : prop = 0 : end if %n $&  
    $iif($prop != raw,prop = tmp(0) & ": " & prop) %n $&
    result = result & prop & %sep %n $&
    next %n $&
    result = left(result,len(result) - len( %sep ))
  if ($com(%mss,executestatement,1,bstr*,%t)) && ($com(%mss,eval,3,bstr*,result)) %result = $com(%mss).result
  else %e Error executing VBScript to retrieve fileinfo.
  :error
  if ($com(%mss)) .comclose %mss
  return %result
}

; Use this alias if you want to use fileinfo on a large collection of files at once
; when used with $findfile on an entire folder and subfolders

alias findfileinfo {
  var %t, %obj = findfileinfo
  if ($1 == initialize) {
    var %e = return $+($chr(3),$color(info),$,findfileinfo:)
    if ($version < 5.91) %e This snippet requires atleast mIRC 5.91
    if ($istok($OS,95 98,32)) %e This snippet can only work on Windows ME or higher.
    if ($2 == $null) %e you must specify properties to retrieve.
    if ($com(%obj)) .comclose %obj
    .comopen %obj MSScriptControl.ScriptControl
    var %sep = $iif($len($3)," $+ $3",vblf), %n = $crlf, %list
    var %props = $&
      Name Size Type DateModified DateCreated DateAccessed Attributes Status Owner Author Title $&
      Subject Category Pages Comments Copyright Artist AlbumTitle Year TrackNumber Genre Duration $&
      BitRate Protected CameraModel DatePictureTaken Dimensions . . EpisodeName ProgramDescription . $&
      Audiosamplesize Audiosamplerate Channels Company Description FileVersion ProductName ProductVersion
    tokenize 32 $2
    while ($0) {
      if ($findtok(%props,$1,1,32)) %list = $addtok(%list,$+(",$1,:,$calc($ifmatch - 1),"),44)    
      tokenize 32 $2-
    }
    if (!%list) %e you didn't specify any valid properties.
    %t = $com(%obj,language,4,bstr*,vbscript)
    %t = $&
      Function FindFileInfo(dir,file) %n $&
      list = array( %list ) %n $&
      set shell = createobject("shell.application") %n $&
      set folder = shell.namespace(dir) %n $&  
      set item = folder.parsename(file) %n $&
      for each index in list %n $&
      tmp = split(index,":") %n $& 
      prop = folder.getdetailsof(item,tmp(1)) %n $& 
      if len(prop) = 0 then : prop = 0 : end if %n $&  
      $iif($prop != raw,prop = tmp(0) & ": " & prop) %n $&
      %obj = %obj & prop & %sep %n $&
      next %n $&
      %obj = left( %obj ,len( %obj ) - len( %sep )) %n $&
      End Function
    %t = $com(%obj,addcode,1,bstr*,%t)
    return $iif(%t == 1,$true,$false)
  }
  elseif ($1 == quit) {
    if ($com(%obj)) .comclose %obj 
  }
  else {
    if ($com(%obj)) {
      %t = $+(FindFileInfo,$chr(40),",$nofile($1),",$chr(44),",$nopath($1),") )
      %t = $com(%obj,eval,3,bstr*,%t)
      return $com(%obj).result
    }
  }
}

alias listtags {
  if ($version < 6.14) return
  var %t = $ticks, %i = 0
  var %objShell = a $+ %t, %objFolder = b $+ %t
  .comopen %objShell shell.application
  if (!$comerr) {
    %t = $com(%objShell,namespace,1,bstr,$mircdir,dispatch* %objFolder)
    if ($com(%objFolder)) {
      echo -ac info * Listing available properties on your system...
      while (%i < 40) {
        %t = $com(%objFolder,getdetailsof,1,bstr*,null,uint,%i)
        echo -a Index %i - $com(%objFolder).result
        inc %i
      }
      .comclose %objFolder
    }
    .comclose %objShell
  }
}

Comments

Sign in to comment.
Yoinx   -  Jan 07, 2006

I agree with Tank. I havent seen anything that you\'ve posted (here or at mircscripts.org) that isnt amazing.

 Respond  
FiberOPtics   -  Jan 04, 2006

Thank you tank59, I appreciate your comment.

I\'ve got a lot more snippets to submit, all of which provide something unique in mIRC that you won\'t find with \"regular\" scripting.

 Respond  
tank59   -  Jan 04, 2006

You\'re an amazing coder, FiberOPtics. Glad that you decided to join us here at hawkee. :)

 Respond  
FiberOPtics   -  Jan 04, 2006

The primary reason that I made this was to read information about .wma files btw, something mIRC doesn\'t support. All the other properties were just a nice extra :)

 Respond  
FiberOPtics   -  Jan 04, 2006

It supports id3v2 if your Windows Explorer supports it. On my comp it does.

There\'s no option to specify what kind of tags to read in Windows as far as I know.

 Respond  
Yoinx   -  Jan 04, 2006

Just curious about the audio file portion.. I know mirc doesnt support Id3v2 tags.... would this? And would you have to specify anything to on which tag to read?

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.