Filexpro() : File Extended Properties Object

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Filexpro() : File Extended Properties Object

11 Dec 2018, 16:31

The function was written in/for Windows 7 + AHK 1.1.30.00

Code: Select all

Filexpro( sFile := "", Kind := "", P* ) {           ; v.90 By SKAN on D1CC @ goo.gl/jyXFo9
Local
Static xDetails 

  If ( sFile = "" )
    {                                                           ;   Deinit static variable
        xDetails := ""
        Return
    }
  
  fex := {}, _FileExt := "" 

  Loop, Files, % RTrim(sfile,"\*/."), DF 
    {
        If not FileExist( sFile:=A_LoopFileLongPath )
          {
              Return
          } 

        SplitPath, sFile, _FileExt, _Dir, _Ext, _File, _Drv

        If ( p[p.length()] = "xInfo" )                          ;  Last parameter is xInfo 
          {
              p.Pop()                                           ;         Delete parameter
              fex.SetCapacity(11)                               ; Make room for Extra info
              fex["_Attrib"]    := A_LoopFileAttrib
              fex["_Dir"]       := _Dir
              fex["_Drv"]       := _Drv
              fex["_Ext"]       := _Ext
              fex["_File"]      := _File
              fex["_File.Ext"]  := _FileExt
              fex["_FilePath"]  := sFile
              fex["_FileSize"]  := A_LoopFileSize
              fex["_FileTimeA"] := A_LoopFileTimeAccessed
              fex["_FileTimeC"] := A_LoopFileTimeCreated
              fex["_FileTimeM"] := A_LoopFileTimeModified
          }              
        Break            
    }

  If Not ( _FileExt )                                   ;    Filepath not resolved
    {
        Return
    }        

  
  objShl := ComObjCreate("Shell.Application")
  objDir := objShl.NameSpace(_Dir) 
  objItm := objDir.ParseName(_FileExt) 
                                                                
  If ( VarSetCapacity(xDetails) = 0 )                           ;     Init static variable
    {
        i:=-1,  xDetails:={},  xDetails.SetCapacity(309)
        
        While ( i++ < 309 )
          {
            xDetails[ objDir.GetDetailsOf(0,i) ] := i
          } 

        xDetails.Delete("")
    }

  If ( Kind and Kind <> objDir.GetDetailsOf(objItm,11) )        ;  File isn't desired kind  
    {
        Return
    }

  i:=0,  nParams:=p.Count(),  fex.SetCapacity(nParams + 11) 

  While ( i++ < nParams )
    {
        Prop := p[i]
        
        If ( (Dot:=InStr(Prop,".")) and (Prop:=(Dot=1 ? "System":"") . Prop) )
          {
              fex[Prop] := objItm.ExtendedProperty(Prop)
              Continue 
          }
          
        If ( PropNum := xDetails[Prop] ) > -1
          {
              fex[Prop] := ObjDir.GetDetailsOf(objItm,PropNum)
              Continue 
          }  
    }
  
  fex.SetCapacity(-1)
Return fex  

} ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Parameters:

sFile: Filepath. Relative path will be resolved to fullpath. Function will return null if Root drive is passed.
Kind: Optional. The "kind" of file. Eg: Music Picture etc. The function will test for Kind before attempting to retrieve properties.
*p: Varadic parameters. Pass property names as strings. I'm able to pass 1317 element linear array as params.
if last variadic parameter is xInfo the function will return extra file props like A_LoopFileExt, A_LoopFileFullPath etc

Here follows the combined list of Windows Property System canonical names + Explorer Listview column header names (I used for brute-force testing).
1317 file property names

Screenshot of Explorer showing Property names. Dates fields are the biggest problem as it will be formatted as per Locale

Image

The Explorer column names are index based and the indices vary between different version of windows.
List of Explorer column names (with index)


Usage Examples:


Example 1:

Code: Select all

Obj := Filexpro( A_AhkPath,, "System.FileFRN" )
DriveGet, Serial, Serial, % SubStr(A_AhkPath,1,2)
MsgBox % Format( "{:08X}-{:016X}", Serial, obj["System.FileFRN"] ) ; File ID
Example 2:

Code: Select all

Obj := Filexpro(A_WinDir . "\Media\chimes.wav",, "System.Audio.ChannelCount" 
                                               , "System.Audio.Compression"                  	
                                               , "System.Audio.EncodingBitrate"              	
                                               , "System.Audio.Format"                       	
                                               , "System.Audio.IsVariableBitRate"            	
                                               , "System.Audio.PeakValue"                    	
                                               , "System.Audio.SampleRate"                   	
                                               , "System.Audio.SampleSize"                   	
                                               , "System.Audio.StreamName"                   	
                                               , "System.Audio.StreamNumber" )                 	
MsgBox % obj["System.Audio.EncodingBitrate"]
Example 3:

Code: Select all

Props := ["Path","Copyright","File description","File version"
        ,"Language","Product name","Product version" ]

Loop, Files, %A_AhkPath%\..\*.*
  {
      Obj := Filexpro( A_LoopFileLongPath, "Program", Props* )

      If ( IsObject(Obj)= 0 )
        Continue
      
      L := ""
      For Key, Val in Obj
        L .= Key A_Tab Val "`n"

      MsgBox, 0, %A_LoopFileName%,  %L%        
  }
My Scripts and Functions: V1  V2
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: Filexpro() : File Extended Properties as Object

11 Dec 2018, 17:05

Thanks as always, SKAN.
I'm running 1.1.30.01 64-bit, and Example 2 has some blank msgbox messages where shown below, and System.Audio.Format shows a UUID. I imagine that's because that info isn't there (or in the case of the UUID, is correct), but in case these aren't the intended result, I thought it would be worth pointing out.

Code: Select all

#Include FileExPro.ahk

Obj := Filexpro(A_WinDir . "\Media\chimes.wav",, "System.Audio.ChannelCount" 
                                               , "System.Audio.Compression"    ;blank              	
                                               , "System.Audio.EncodingBitrate"              	
                                               , "System.Audio.Format"          ; GUID             	
                                               , "System.Audio.IsVariableBitRate"  ; blank          	
                                               , "System.Audio.PeakValue"     ; blank               	
                                               , "System.Audio.SampleRate"                   	
                                               , "System.Audio.SampleSize"                   	
                                               , "System.Audio.StreamName"   ; blank                	
                                               , "System.Audio.StreamNumber" )                 	
MsgBox % obj["System.Audio.StreamName"]
I always appreciate your contributions.
Regards,
burque505
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Filexpro() : File Extended Properties as Object

11 Dec 2018, 17:50

Hi burque505
System.Audio.Format shows a UUID.
In GDI+, PNG JPEG etc needs to be id'ed with a UUID. I guess this is similar to that.
Yes, I knew about the blanks. I haven't tested the function with music files. My main target is Image and Photo.
And even with that, Windows doesn't seem to read GPS tags correctly (I inserted with ExifTool).

If you or someone else can test Audio and Music, it would be helpful to the community.

Thanks for the valuable feedback. :)
My Scripts and Functions: V1  V2
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Re: Filexpro() : File Extended Properties Object

13 Dec 2018, 04:43

I Always Hold My Tongue With Your Scripts Because They're Just Too Awesome And That's self evident. But this one solved an immediate need for me,so THANKS MUCH DUDE As Always...

And there seems to be a lot of blanks for Audio, info is otherwise there,it's visible with MediaInfo & ffmpeg...
live ? long & prosper : regards
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Filexpro() : File Extended Properties Object

13 Dec 2018, 09:23

:)
there seems to be a lot of blanks for Audio, info is otherwise there,it's visible with MediaInfo & ffmpeg...
These properties are to meant to be shown in Windows Explorer and searched with "Advanced Query Syntax".
If Explorer could show all properties for all file formats, it would become horribly slow/unusable and may become unstable
when trying to read a badly written property.
These methods use simple lookup and shouldn't be compared with professional level software.

BUT.. I do feel these methods have been poorly implemented. When it works, it works fantastic.

Thanks for the feedback :)
My Scripts and Functions: V1  V2
User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

Re: Filexpro() : File Extended Properties Object

30 May 2020, 17:16

Hi @SKAN, thank you for this, it's amazing!

I've been able to pull almost every attribute of a music file, but for some reason, I just can't get the artist?

In my music files, it puts the artist name under "Contributing artists". I had a bit of a look online, and found this link -
1. If the AlbumArtist property of the song contains a value, the value of the AlbumArtist property is returned.
2. If the AlbumArtist property of the song does not contain a value, and the song is marked as part of a compilation, the value "Various Artists" is returned.
Otherwise, the first value from the contributing artists list is returned. The contributing artists list is the value of the System.Music.Artist file property. If you want to get the album artist, use AlbumArtist instead.
I tested this on an mp3 file, and if the artist name was in AlbumArtist, it worked fine. However, with the artist name in Contributing Artists, it wouldn't return anything. Any ideas?

Code: Select all

Obj := Filexpro("F:\iPod Library\3 Doors Down\Away From The Sun\Here Without You.mp3",, "System.Music.AlbumTitle" 
                                                                                      , "System.Music.Genre"                  	
									                                                  , "System.Music.Artist"
								                                                      , "System.Music.TrackNumber" ) 

Obj2 := Filexpro("F:\iPod Library\3 Doors Down\Away From The Sun\Here Without You.mp3",, "System.FileName" )

TrimmedName := SubStr(Obj2["System.FileName"],1,StrLen(Obj2["System.FileName"])-4)
ArtistIs := Obj["System.Music.Artist"]

Msgbox % "Song is: "TrimmedName "`nArtist is: " ArtistIs "`nAlbum is: "obj["System.Music.AlbumTitle"] "`nTrack Number is: "obj["System.Music.TrackNumber"] "`nGenre is: "obj["System.Music.Genre"]


____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Filexpro() : File Extended Properties Object

31 May 2020, 15:01

Hi @submeg, thanks for the feedback.
submeg wrote:I tested this on an mp3 file, and if the artist name was in AlbumArtist, it worked fine. However, with the artist name in Contributing Artists, it wouldn't return anything. Any ideas?
Absolutely no idea about music files.. Sorry! :(.
I use this mostly for photos.
My Scripts and Functions: V1  V2
User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

Re: Filexpro() : File Extended Properties Object

31 May 2020, 15:14

@SKAN, Ah damn! Do you know of any other resources? If I can get this to work, I'll be able to build a file comparison tool for two hard drives of music, so extremely keen!
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Filexpro() : File Extended Properties Object

31 May 2020, 15:44

submeg wrote:Do you know of any other resources?
Again.. No idea. I've tried AudioGenie DLL a decade ago.. Not sure if its a viable option, today.
My Scripts and Functions: V1  V2
User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

Re: Filexpro() : File Extended Properties Object

31 May 2020, 15:51

SKAN wrote:
31 May 2020, 15:44
submeg wrote:Do you know of any other resources?
Again.. No idea. I've tried AudioGenie DLL a decade ago.. Not sure if its a viable option, today.
Sorry, I meant to learn more about the options for File Extended Properties, just so I can figure out if it's a syntax issue.
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Filexpro() : File Extended Properties Object

31 May 2020, 16:27

submeg wrote:I meant to learn more about the options for File Extended Properties, just so I can figure out if it's a syntax issue.
The link you've provided points to Namespace: Windows.Storage.FileProperties (Windows 10)
This function deals with only System properties.
My Scripts and Functions: V1  V2
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Filexpro() : File Extended Properties Object

10 Jun 2020, 06:36

@SKAN OK, now after all folks have thanked you already I have to say: "You like spiders?!!!" :clap: (taken from the screenshot image).
You're my hero. From now on your nick reads SpiderManKAN for me :mrgreen: :thumbup:
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Filexpro() : File Extended Properties Object

10 Jun 2020, 08:25

Thanks for the nice words BoBo :)
BoBo wrote:"You like spiders?!!!" :clap:
Yes, here is a stunning one:
Spoiler
My Scripts and Functions: V1  V2
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: Filexpro() : File Extended Properties Object

10 Jun 2020, 09:49

@SKAN
That one is DEFINITELY radioactive ... hmmm.... :-D
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Filexpro() : File Extended Properties Object

11 Jun 2020, 01:45

TheArkive wrote:That one is DEFINITELY radioactive ... hmmm.... :-D
It is :D
My Scripts and Functions: V1  V2
User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

Re: Filexpro() : File Extended Properties Object

27 Jun 2020, 19:27

SKAN wrote:
31 May 2020, 16:27
submeg wrote:I meant to learn more about the options for File Extended Properties, just so I can figure out if it's a syntax issue.
The link you've provided points to Namespace: Windows.Storage.FileProperties (Windows 10)
This function deals with only System properties.
Hi @SKAN,

I've been able to find/create a workaround for what I was trying to use FileExPro for:
  • Found this handy tool: Listary, which is an amazing search tool for your files in Windows
  • Created a script to pull the name of the currently selected file/folder
Script to select the file/folder name:

Code: Select all


PerformAction_CopyFolderName()
{

	Send, {AppsKey}
	Sleep, 25
	Send, m
	Sleep, 25 
	Send, ^c
	Sleep, 5 
	Send, {Esc}
	
	msg := "Folder name copied."
	ToolTip, %msg%
	SetTimer, RemoveToolTip, -700
	msg := ""

}
Return

Not as automated as I would've hoped for, but much better than manually searching!

submeg
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Filexpro() : File Extended Properties Object

01 Jul 2020, 15:53

submeg wrote:I've been able to find/create a workaround
Glad to know. thanks for sharing info. :)
My Scripts and Functions: V1  V2
User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Re: Filexpro() : File Extended Properties Object

01 Jul 2020, 16:45

This is great! Is it possible to extract the geolocation (Latitude & Longitude) from a photo using Filexpro() ?
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Filexpro() : File Extended Properties Object

01 Jul 2020, 17:15

SirSocks wrote:
01 Jul 2020, 16:45
This is great! Is it possible to extract the geolocation (Latitude & Longitude) from a photo using Filexpro() ?
I wouldn't recommend!. Poorly implemented.
If you want to read GPS from your own camera EXIFX() could work.
If you want to read from "any" photo, an external command line tool ExifTool by Phil Harvey is the best available choice.
My Scripts and Functions: V1  V2
User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Re: Filexpro() : File Extended Properties Object

01 Jul 2020, 19:04

Thank you very much SKAN. Both Filexpro() and EXIFX() are very useful to me. I truly appreciate all of your code that you share. :dance:

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: chinagreenelvis, TheNaviator and 83 guests