Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

FileGetProperties


  • Please log in to reply
20 replies to this topic
majstang
  • Members
  • 387 posts
  • Last active: Sep 27 2015 01:44 PM
  • Joined: 29 Aug 2008
Need some status/update about the possibility to check/read file properties/metadata as a pure ahk solution. Is there something we can use now and avoid external commandline tools? Any pointers to scripts with some generic file-properties feature is very appreciated.

Saw this script for jpg, bmp and Gifs, but cant get it to work.
ImageWxH(ImageFile) {
;Supports only GIF, JPG, BMP
IfNotExist, %ImageFile%
  Return ""
Size=2592
DHW:=A_DetectHiddenWindows
DetectHiddenWindows, ON
Gui, 99:-Caption
Gui, 99:Margin, 0, 0
Gui, 99:Show,Hide w%Size% h%Size%, ImageWxH.Temporary.GUI
Gui, 99:Add, Picture, x0 y0 , % ImageFile
Gui, 99:Show,AutoSize Hide, ImageWxH.Temporary.GUI
WinGetPos, , ,w,h, ImageWxH.Temporary.GUI
Gui, 99:Destroy
DetectHiddenWindows, %DHW%
Return w "x" h
}
<!-- m -->http://www.autohotke... ... d metadata<!-- m -->

Gast (w/ nick)
  • Members
  • 119 posts
  • Last active: Aug 02 2013 06:52 AM
  • Joined: 28 Nov 2005
The script works for me.
As an example I put a bmp-file into
my c:\temp\ folder and then ran the
script like this.

The image size was returned correctly.

result := ImageWxH("c:\temp\image.bmp")
msgbox, %result%
return


ImageWxH(ImageFile) {
;Supports only GIF, JPG, BMP
IfNotExist, %ImageFile%
  Return ""
Size=2592
DHW:=A_DetectHiddenWindows
DetectHiddenWindows, ON
Gui, 99:-Caption
Gui, 99:Margin, 0, 0
Gui, 99:Show,Hide w%Size% h%Size%, ImageWxH.Temporary.GUI
Gui, 99:Add, Picture, x0 y0 , % ImageFile
Gui, 99:Show,AutoSize Hide, ImageWxH.Temporary.GUI
WinGetPos, , ,w,h, ImageWxH.Temporary.GUI
Gui, 99:Destroy
DetectHiddenWindows, %DHW%
Return w "x" h
}


majstang
  • Members
  • 387 posts
  • Last active: Sep 27 2015 01:44 PM
  • Joined: 29 Aug 2008
Yes, you are right! I didnt use the return after msgbox.
However, Im looking for a way to retrieve which video-compression a .TS file uses (H.264 or MPEG2) and with this script that would be impossible to achieve. This script works as inspiration retrieving file-properties only by using autohotkey is possible. Maybe there is some script you know of that can do what im after without using an external file analyzer (only autohotkey scripts)?

shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006
here <!-- w -->www.autohotkey.com/forum/topic66634.html<!-- w -->
first method, modify to suit your needs
If i've seen further it is by standing on the shoulders of giants

my site | ~shajul | WYSIWYG BBCode Editor

majstang
  • Members
  • 387 posts
  • Last active: Sep 27 2015 01:44 PM
  • Joined: 29 Aug 2008
Many thanks for tip :)
Sadly i cant go with Autohotkey_L, cuz many of my old and most important scripts does not work with it and im too much of a noob to be abled to convert them.
Any tip of same kind of scripts working with ahk_basic?

swanbird
  • Members
  • 8 posts
  • Last active: Dec 11 2012 06:25 AM
  • Joined: 24 Oct 2010
What about tyring to use MediaInfo.dll to get the video compression information? Check out this topic: http://www.autohotke...pic.php?t=66500

majstang
  • Members
  • 387 posts
  • Last active: Sep 27 2015 01:44 PM
  • Joined: 29 Aug 2008
Yes, I did see this script when searching around in forum. It requires external tools to make it work, but if there isnt any other script out there working with ahk_basic I go with it. Thanks for your help guys :)

majstang
  • Members
  • 387 posts
  • Last active: Sep 27 2015 01:44 PM
  • Joined: 29 Aug 2008

here <!-- w -->www.autohotkey.com/forum/topic66634.html<!-- w -->
first method, modify to suit your needs

Hi shajul!
Wow, this is a great pice of script! Trying to remove the GUI and only get fileproperties into a variable, but am not entirely sure how to do that. Could you help me out with some pointers?

/*           ,---,                                          ,--,    
           ,--.' |                                        ,--.'|    
           |  |  :                      .--.         ,--, |  | :    
  .--.--.  :  :  :                    .--,`|       ,'_ /| :  : '    
 /  /    ' :  |  |,--.  ,--.--.       |  |.   .--. |  | : |  ' |    
|  :  /`./ |  :  '   | /       \      '--`_ ,'_ /| :  . | '  | |    
|  :  ;_   |  |   /' :.--.  .-. |     ,--,'||  ' | |  . . |  | :    
 \  \    `.'  :  | | | \__\/: . .     |  | '|  | ' |  | | '  : |__  
  `----.   \  |  ' | : ," .--.; |     :  | |:  | : ;  ; | |  | '.'| 
 /  /`--'  /  :  :_:,'/  /  ,.  |   __|  : ''  :  `--'   \;  :    ; 
'--'.     /|  | ,'   ;  :   .'   \.'__/\_: |:  ,      .-./|  ,   /  
  `--'---' `--''     |  ,     .-./|   :    : `--`----'     ---`-'   
                      `--`---'     \   \  /                         
                                    `--`-'  
------------------------------------------------------------------
Function: Find Exif Info of image
Requires: OS >= Win XP
          Autohotkey_L
URL: http://www.autohotkey.com/forum/viewtopic.php?t=66634
------------------------------------------------------------------
*/


inFileName := "E:\TV\Recording Service\20110217_20-59-01_TV4 Plus_Älskade spion.ts"

SplitPath,inFileName,sFileName,sFileDir
objShell := ComObjCreate("Shell.Application") 
objFolder := objShell.Namespace(sFileDir . "") 
objFilename := objFolder.Parsename(sFileName)


;Gui, Add, ListView, x0 y0 r45 w400 h500 vMyLV, Attribute|Value

;GuiControl, -Redraw, MyLV 
Loop
{
   iAttribute := objFolder.GetDetailsOf(objFolder.Items, A_Index)
   if (iValue := objFolder.GetDetailsOf(objFilename, A_Index)) ;only add attribs with values
      LV_Add("",iAttribute,iValue)
} until iAttribute = ""
;GuiControl, +Redraw, MyLV 

;LV_ModifyCol()
;Gui, Show, w400 h500, File Details

msgbox, % ??
return

/*
ShowExifOnly:
exiflist := 1
MsgBox, Now showing only Exif details..
LV_Delete()
exif = 
( LTrim Join    ;Exif Attributes
Size,Perceived type,Kind,Date taken,Rating,Authors,Title,Subject,Categories,
 Comments,Copyright,Camera model,Dimensions,Camera maker,Filename,Bit depth,
   Horizontal resolution,Width,Vertical resolution,Height,Type,EXIF version,
Exposure bias,Exposure program,Exposure time,F-stop,Flash mode,Focal length,
35mm focal length,ISO speed,Lens maker,Lens model,Light source,Max aperture,
Metering mode,Orientation,Program mode,Saturation,Subject distance,White balance
)

GuiControl, -Redraw, MyLV 
Loop
{
   iAttribute := objFolder.GetDetailsOf(objFolder.Items, A_Index)
   If iAttribute in %exif%
      if (iValue := objFolder.GetDetailsOf(objFilename, A_Index)) ;only add attribs with values
         LV_Add("",iAttribute,iValue)
} until iAttribute = ""

GuiControl, +Redraw, MyLV 
Return

GuiClose:
if not exiflist
   gosub ShowExifOnly
else
   ExitApp
return
*/


shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006
inFileName := "E:\TV\Recording Service\20110217_20-59-01_TV4 Plus_Älskade spion.ts"



SplitPath,inFileName,sFileName,sFileDir

objShell := ComObjCreate("Shell.Application") 

objFolder := objShell.Namespace(sFileDir . "\") 

objFilename := objFolder.Parsename(sFileName)

oDetails := Object()



Loop

{

  iAttribute := objFolder.GetDetailsOf(objFolder.Items, A_Index)

  if (iAttribute = "")

  break

  if (iValue := objFolder.GetDetailsOf(objFilename, A_Index)) ;only add attribs with values

    oDetails[iAttribute] := iValue

}



;; Get only ones you require ---------------

MsgBox % oDetails.Attributes      ; attributes

MsgBox % oDetails["Frame rate"]   ; frame rate



;; or get all details ----------------------

For attribute,value in oDetails

  MsgBox % attribute . " = " . value

If i've seen further it is by standing on the shoulders of giants

my site | ~shajul | WYSIWYG BBCode Editor

majstang
  • Members
  • 387 posts
  • Last active: Sep 27 2015 01:44 PM
  • Joined: 29 Aug 2008
One word...Fantastic :D
Having one problem though! This first thing is a non-problem however. Since your code is going to be used on OS:es with many different languages I cant retrieve one by one values, cuz it wouldnt work if not having swedish windows:
;; Get only ones you require ---------------
MsgBox % oDetails.Attribut      ; attributes
MsgBox % oDetails["Videokomprimering"]   ; videocompression
MsgBox % oDetails["Filnamn"]   ; file name

This second thing is the one im planning to use, but the use of "For attribute,value in oDetails" threw me a bit. It makes all the values to pop up in equaly as many msgboxes as there are values and not all values in one single msgbox. When having all values in one variable Im planning to use some stringmanagement on it to retrieve the info Im after, in order to get around the launguage issue. How would you commence getting all values in a single msgbox and spacing them up with some "`n`n" ? Tried around different approaches, but non worked for me. Sorry, im such a noob :oops:
;; or get all details ----------------------
For attribute,value in oDetails
  MsgBox % attribute . " = " . value


shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006
inFileName := "E:\TV\Recording Service\20110217_20-59-01_TV4 Plus_Älskade spion.ts"

SplitPath,inFileName,sFileName,sFileDir
objShell := ComObjCreate("Shell.Application") 
objFolder := objShell.Namespace(sFileDir . "\") 
objFilename := objFolder.Parsename(sFileName)
oDetails := Object()

Loop
{
  iAttribute := objFolder.GetDetailsOf(objFolder.Items, A_Index)
  if (iAttribute = "")
    break
  if (iValue := objFolder.GetDetailsOf(objFilename, A_Index)) ;only add attribs with values
    details .= iAttribute . " = " . iValue . "`n"
}
MsgBox % details

One other method you can try is have language files for all languages you plan to support. You can determine the language using the code below
SetFormat, integer, H
slocale := DllCall("GetSystemDefaultLCID")
ulocale := DllCall("GetUserDefaultLCID")
tlocale := DllCall("GetThreadLocale")
MsgBox % "system locale : " . slocale 
         . "`nuser locale :" . ulocale
         . "`nthread locale : " . tlocale
SetFormat, integer, D
Language codes here -> <!-- m -->http://msdn.microsof...l/bb896001.aspx<!-- m -->
If i've seen further it is by standing on the shoulders of giants

my site | ~shajul | WYSIWYG BBCode Editor

majstang
  • Members
  • 387 posts
  • Last active: Sep 27 2015 01:44 PM
  • Joined: 29 Aug 2008
Far out :D
Excellent suggestion about languages also. If I stumble upon my original plan this is the way to go for sure.
Shajul, you are great! Many thanks for your help.

majstang
  • Members
  • 387 posts
  • Last active: Sep 27 2015 01:44 PM
  • Joined: 29 Aug 2008
Greetings shajul!
I stumbled onto some problems, i didn't anticipated, with your fileproperty function :?
It works great as long as only putting in one inFileName into the function, but when putting in a second one the fileproperty list/details from file 1 gets merged with details for file 2. Im using your script inside a Gosub label and are putting in inFileNames through a number of If/Else statements with Gosub. When one inFilename has been processed in Label: script goes back to next If/Else and picks up InFileName 2 and sends it to the Gosub Label again. What seem to happen is the fileproperty function is not set to zero when a new inFileName is about to be processed, but saves/keeps the fileproperty details from first processing in memory. This data is then added/merged to fileproperty details for inFileName 2. Is there a way to fix this behaviour, do you think?

shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006

I stumbled onto some problems, i didn't anticipated, with your fileproperty function :?


It was never a function, just a demo of how it could be done, to be adapted to your needs.

Anyway, here is a function that you may adapt to your needs. (or post your complete source code, so that i can tell you what will be the best method for you)

;--- Example ---
Loop, %A_WinDir%\*.*
{
	MsgBox, 4, %A_LoopFileName%, % GetDetailsOf(A_LoopFileFullPath) . "`n`n Continue?"
	IfMsgBox, No
			ExitApp
}

;--- Function ---
GetDetailsOf(inFileName) {
	SplitPath,inFileName,sFileName,sFileDir
	objFolder := ComObjCreate("Shell.Application").Namespace(sFileDir . "")
	objFile := objFolder.Parsename(sFileName)
	Loop
	{
		iAttribute := objFolder.GetDetailsOf(objFolder, A_Index)
		if not iAttribute
			break
		if (iValue := objFolder.GetDetailsOf(objFile, A_Index)) ;only add attribs with values
			details .= A_Index . " : " . iAttribute . " = " . iValue . "`n"
	}
	return details, objFolder := "", objFile := ""
}

If i've seen further it is by standing on the shoulders of giants

my site | ~shajul | WYSIWYG BBCode Editor

majstang
  • Members
  • 387 posts
  • Last active: Sep 27 2015 01:44 PM
  • Joined: 29 Aug 2008
Wow, cool code :D
Having problems though to adapt it to what im after, sorry for my noobness :oops:

Well, this code below is close to what im looking for. Cant get the function to work however. Had to forget about using a function in a label also (yes, im learning the hard way :wink: ), so i disabled gosub.
latest1 := "E:\TV\Recording Service\20110217_20-59-01_TV4 Plus_Älskade spion.ts"
latest2 := "E:\TV\Recording Service\20110218_19-59-02_SVT1 HD_På spåret.ts"

If latest1=
   ExitApp
Else
  {
   inFileName := latest1
   ;Gosub, Label1
   GetDetailsOf(inFileName)
   file1_properties := inFileName
   Msgbox % file1_properties
  }
If latest2=
   ExitApp
Else
  { 
   inFileName := latest2
   ;Gosub, Label1
   GetDetailsOf(inFileName)
   file2_properties := inFileName
   Msgbox % file2_properties
  }


;Label1:
;--- Function ---
GetDetailsOf(inFileName) {
   SplitPath,inFileName,sFileName,sFileDir
   objFolder := ComObjCreate("Shell.Application").Namespace(sFileDir . "\")
   objFile := objFolder.Parsename(sFileName)
   Loop
   {
      iAttribute := objFolder.GetDetailsOf(objFolder, A_Index)
      if not iAttribute
         break
      if (iValue := objFolder.GetDetailsOf(objFile, A_Index)) ;only add attribs with values
         details .= A_Index . " : " . iAttribute . " = " . iValue . "`n"
   }
   return details, objFolder := "", objFile := ""
}