Jump to content

_FileGetProperty - Retrieves the properties of a file


BrewManNH
 Share

Recommended Posts

This is a modification of a script that was originally posted back in 2006, that was itself a modification of a script in the same thread, which was a modification of another script linked in that thread. All credits remain in the header as to who contributed to this.

The only credit I take in this script is modifying parts of it to:

1.make it a bit faster, by removing a ReDim that was inside a loop

2.add support for OSs other than XP because of the number of file properties returned

3.add support for the future if the number of file properties returned changes again with future versions of Windows

Please take note, this script will only work if you know the name of the property you're trying to retrieve. These properties are dependent upon the OS version, the OS language, and the file's properties. This function does not take any of these things into account, if you want to use this and make it OS neutral, you'll have to do that in your script, because it doesn't get done in here. Fortunately, if you access this function and leave the parameter $FGP_Property blank, it will return an array of all the properties that Windows knows about, and in the language that Windows is running in.

Windows XP only returns 38 properties, Windows 7 returns 288, Windows 8 returns 290. The same properties can have different names depending on which OS you're using this with.

Update Sept. 6, 2017

Changed the code slightly to make sure the return includes all properties, the last update cut off some of the properties at the end, and increased the $iPropertyCount to 500 (from 300) because of Windows 10 file property count increase.

Update: Jun-25-2013

I have tweaked this function again, a small update.

  • Added a new parameter to the function, $iPropertyCount, with a default setting of 300. This parameter was previously hard coded inside the function, now you are able to adjust it to the setting you desire/require. This value is used to determine how many file properties will be searched for the value passed in $FGP_PROPERTY, or the maximum amount of properties that will be returned in the array if $FGP_PROPERTY is a blank string.
  • The $FGP_PROPERTY parameter will now accept the Default keyword in place of a blank string, which tells the function to return an array of all known properties, up to the setting of $iPropertyCount.

Update: Feb-11-2013

I have updated this function again.

  • Now it has a single point of return, except for error exceptions, instead of multiple places that it returned from previously.
  • I've renamed the variables used so that they'll be less chance of a name collision with someone's script.
  • Fixed a small bug that added a blank line to the end of the array returned when getting all properties.
  • Changed the return value on an error from 0 to an empty string.

NOTE: This is a repost of a thread I had already posted last year. I went looking for it today to update the code in it, and found that it had disappeared.

New code

#include <File.au3> ; only used for the example script, not needed for the UDF
#include <Array.au3> ; only used for the example script, not needed for the UDF
#include <Constants.au3> ; only used for the MsgBox, not needed for the UDF
$sFolder = FileSelectFolder("Select a folder to scan", "")
$sFolder &= ""
$aFiles = _FileListToArray($sFolder, "*.exe")
For $I = 1 To $aFiles[0]
    $aDetails = _FileGetProperty($sFolder & "\" & $aFiles[$I]) ; Returns an array with all properties of the file
    _ArrayDisplay($aDetails)
Next
Global $sDetails = _FileGetProperty($sFolder & "\" & $aFiles[$aFiles[0]], "date modified")
MsgBox($MB_SYSTEMMODAL, "Date Modified", $sDetails)
;===============================================================================
; Function Name.....: _FileGetProperty
; Description.......: Returns a property or all properties for a file.
; Version...........: 1.0.2
; Change Date.......: 05-16-2012
; AutoIt Version....: 3.2.12.1+
; Parameter(s)......: $FGP_Path - String containing the file path to return the property from.
;                     $FGP_PROPERTY - [optional] String containing the name of the property to return. (default = "")
;                     $iPropertyCount - [optional] The number of properties to search through for $FGP_PROPERTY, or the number of items
;                                       returned in the array if $FGP_PROPERTY is blank. (default = 300)
; Requirements(s)...: None
; Return Value(s)...: Success: Returns a string containing the property value.
;                     If $FGP_PROPERTY is blank, a two-dimensional array is returned:
;                         $av_array[0][0] = Number of properties.
;                         $av_array[1][0] = 1st property name.
;                         $as_array[1][1] = 1st property value.
;                         $av_array[n][0] = nth property name.
;                         $as_array[n][1] = nth property value.
;                     Failure: Returns an empty string and sets @error to:
;                       1 = The folder $FGP_Path does not exist.
;                       2 = The property $FGP_PROPERTY does not exist or the array could not be created.
;                       3 = Unable to create the "Shell.Application" object $objShell.
; Author(s).........: - Simucal <Simucal@gmail.com>
;                     - Modified by: Sean Hart <autoit@hartmail.ca>
;                     - Modified by: teh_hahn <sPiTsHiT@gmx.de>
;                     - Modified by: BrewManNH
; URL...............: http://www.autoitscript.com/forum/topic/34732-udf-getfileproperty/page__view__findpost__p__557571
; Note(s)...........: Modified the script that teh_hahn posted at the above link to include the properties that
;                     Vista and Win 7 include that Windows XP doesn't. Also removed the ReDims for the $av_ret array and
;                     replaced it with a single ReDim after it has found all the properties, this should speed things up.
;                     I further updated the code so there's a single point of return except for any errors encountered.
;                     $iPropertyCount is now a function parameter instead of being hardcoded in the function itself.
;===============================================================================
Func _FileGetProperty($FGP_Path, $FGP_PROPERTY = "", $iPropertyCount = 500)
    If $FGP_PROPERTY = Default Then $FGP_PROPERTY = ""
    $FGP_Path = StringRegExpReplace($FGP_Path, '["'']', "") ; strip the quotes, if any from the incoming string
    If Not FileExists($FGP_Path) Then Return SetError(1, 0, "") ; path not found
    Local Const $objShell = ObjCreate("Shell.Application")
    If @error Then Return SetError(3, 0, "")
    Local Const $FGP_File = StringTrimLeft($FGP_Path, StringInStr($FGP_Path, "\", 0, -1))
    Local Const $FGP_Dir = StringTrimRight($FGP_Path, StringLen($FGP_File) + 1)
    Local Const $objFolder = $objShell.NameSpace($FGP_Dir)
    Local Const $objFolderItem = $objFolder.Parsename($FGP_File)
    Local $Return = "", $iError = 0
    If $FGP_PROPERTY Then
        For $I = 0 To $iPropertyCount
            If $objFolder.GetDetailsOf($objFolder.Items, $I) = $FGP_PROPERTY Then
                $Return = $objFolder.GetDetailsOf($objFolderItem, $I)
            EndIf
        Next
        If $Return = "" Then
            $iError = 2
        EndIf
    Else
        Local $av_ret[$iPropertyCount + 1][2] = [[0]]
        For $I = 1 To $iPropertyCount
            If $objFolder.GetDetailsOf($objFolder.Items, $I) Then
                $av_ret[$I][0] = $objFolder.GetDetailsOf($objFolder.Items, $I - 1)
                $av_ret[$I][1] = $objFolder.GetDetailsOf($objFolderItem, $I - 1)
;~              $av_ret[0][0] += 1
                $av_ret[0][0] = $I
            EndIf
        Next
        ReDim $av_ret[$av_ret[0][0] + 1][2]
        If Not $av_ret[1][0] Then
            $iError = 2
            $av_ret = $Return
        Else
            $Return = $av_ret
        EndIf
    EndIf
    Return SetError($iError, 0, $Return)
EndFunc   ;==>_FileGetProperty

Warning, old code below.

Spoiler
#include <File.au3> ; only used for the example script, not needed for the UDF
#include <Array.au3> ; only used for the example script, not needed for the UDF
$sFolder = FileSelectFolder("Select a folder to scan", "")
$sFolder &= ""
$aFiles = _FileListToArray($sFolder)
For $I = 1 To $aFiles[0]
$aDetails = _FileGetProperty($sFolder & $aFiles[$I]) ; Returns an array with all properties of the file
_ArrayDisplay($aDetails)
ConsoleWrite("File size of " & $sFolder & $aFiles[$I] & " = " & _FileGetProperty($sFolder & $aFiles[$I], "size") & @CRLF) ; displays in the console the Size of the file
Next

;===============================================================================
; Function Name.....: _FileGetProperty
; Description.......: Returns a property or all properties for a file.
; Version...........: 1.0.2
; Change Date.......: 05-16-2012
; AutoIt Version....: 3.2.12.1+
; Parameter(s)......: $FGP_Path - String containing the file path to return the property from.
;                     $FGP_PROPERTY - [optional] String containing the name of the property to return. (default = "")
; Requirements(s)...: None
; Return Value(s)...: Success: Returns a string containing the property value.
;                     If $FGP_PROPERTY is empty, an two-dimensional array is returned:
;                         $av_array[0][0] = Number of properties.
;                         $av_array[1][0] = 1st property name.
;                         $as_array[1][1] = 1st property value.
;                         $av_array[n][0] = nth property name.
;                         $as_array[n][1] = nth property value.
;                     Failure: Returns an empty string and sets @error to:
;                       1 = The folder $FGP_Path does not exist.
;                       2 = The property $FGP_PROPERTY does not exist or the array could not be created.
;                       3 = Unable to create the "Shell.Application" object $objShell.
; Author(s).........: - Simucal <Simucal@gmail.com>
;                     - Modified by: Sean Hart <autoit@hartmail.ca>
;                     - Modified by: teh_hahn <sPiTsHiT@gmx.de>
;                     - Modified by: BrewManNH
; URL...............: http://www.autoitscript.com/forum/topic/34732-udf-getfileproperty/page__view__findpost__p__557571
; Note(s)...........: Modified the script that teh_hahn posted at the above link to include the properties that
;                     Vista and Win 7 include that Windows XP doesn't. Also removed the ReDims for the $av_ret array and
;                     replaced it with a single ReDim after it has found all the properties, this should speed things up.
;                     I further updated the code so there's a single point of return except for any errors encountered.
;===============================================================================
Func _FileGetProperty($FGP_Path, Const $FGP_PROPERTY = "")
    $FGP_Path = StringRegExpReplace($FGP_Path, '["'']', "") ; strip the quotes, if any from the incoming string
    If Not FileExists($FGP_Path) Then Return SetError(1, 0, "") ; path not found
    Local Const $objShell = ObjCreate("Shell.Application")
    If @error Then Return SetError(3, 0, "")
    Local $iPropertyCount = 300 ; arbitrary number used, Windows 7 only returns 288 properties, Windows XP only returns 38 (future proofing)
    Local Const $FGP_File = StringTrimLeft($FGP_Path, StringInStr($FGP_Path, "\", 0, -1))
    Local Const $FGP_Dir = StringTrimRight($FGP_Path, StringLen($FGP_File) + 1)
    Local Const $objFolder = $objShell.NameSpace($FGP_Dir)
    Local Const $objFolderItem = $objFolder.Parsename($FGP_File)
    Local $Return = "", $iError = 0
    If $FGP_PROPERTY Then
        For $I = 0 To $iPropertyCount
            If $objFolder.GetDetailsOf($objFolder.Items, $I) = $FGP_PROPERTY Then
                $Return = $objFolder.GetDetailsOf($objFolderItem, $I)
            EndIf
        Next
        If $Return = "" Then
            $iError = 2
        EndIf
    Else
        Local $av_ret[$iPropertyCount + 1][2] = [[0]]
        For $I = 1 To $iPropertyCount
            If $objFolder.GetDetailsOf($objFolder.Items, $I) Then
                $av_ret[$I][0] = $objFolder.GetDetailsOf($objFolder.Items, $I - 1)
                $av_ret[$I][1] = $objFolder.GetDetailsOf($objFolderItem, $I - 1)
                $av_ret[0][0] += 1
            EndIf
        Next
        ReDim $av_ret[$av_ret[0][0] + 1][2]
        If Not $av_ret[1][0] Then
            $iError = 2
            $av_ret = $Return
        Else
            $Return = $av_ret
        EndIf
    EndIf
    Return SetError($iError, 0, $Return)
EndFunc   ;==>_FileGetProperty

The variable $iPropertyCount is currently set to 300, which is just a number I threw in there to make sure it gets all of the properties of the files under Windows 7 and a little bit of overhead.

Edited by BrewManNH
Updated code to make sure it includes all properties, it was cutting off some of the items.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

:thumbsup:

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Just for completeness, Vista will return 278 properties.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Didn't you create something like this ages ago?

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Yes I did, but the thread doesn't exist any more. I made a note in the OP about it. I wanted to update the code, but couldn't find the thread so I recreated it with the help of the web wayback machine.

Hopefully now, it works as it is supposed to and follows better coding practices learned since then.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

How peculiar, thanks for explaining.

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 4 months later...

Update: Jun-25-2013

I have tweaked this function again, a small update.

  • Added a new parameter to the function, $iPropertyCount, with a default setting of 300. This parameter was previously hard coded inside the function, now you are able to adjust it to the setting you desire/require. This value is used to determine how many file properties will be searched for the value passed in $FGP_PROPERTY, or the maximum amount of properties that will be returned in the array if $FGP_PROPERTY is a blank string.
  • The $FGP_PROPERTY parameter will now accept the Default keyword in place of a blank string, which tells the function to return an array of all known properties, up to the setting of $iPropertyCount.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 5 months later...

I've had a problem with image files.

With tif and jpeg files the following code shows a null field for the dimensions.

Is it my error, a bug, or what?

Running XP SP3

William

Global $Testfile= FileOpenDialog ("Test File","C:\Documents and Settings\Owner\Desktop\SBACC Comp nov2013\possibles","All(*.*)")
Global $sProperties = _FileGetProperty ($Testfile,"width",300)
MsgBox (0,"width", $sProperties)
Global $aProperties = _FileGetProperty ($Testfile,"",300)
_ArrayDisplay ($aProperties)
Edited by saywell
Link to comment
Share on other sites

What problem are you having with it? That works for me, I get a MsgBox showing the width of a *.bmp file when I test it with that. Then I get an _ArrayDisplay dialog showing all properties of the file. What do you get?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I get a msgbox with null entry.

the array shows the property names in Col zero, but only some of the values in col 1.   The dates are all there, the camera model is shown, and the total pixels, but nothing in height or width .

If I mouseover the file in windows explorer, it displays them without a problem.

William

Link to comment
Share on other sites

Is it showing the height and width, or the dimensions "### x ###" when you mouseover it?

Not every file has every property set, most have very few set, so even though it will show the property name there will be nothing showing in the details for that property.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Mouseover shows dimensions, but this isn't listed in the array.  Nor in the file properties shown in irfanview - though the width and height are shown in the EXIF data.

If I right click on the file in explorer  ==> properties  ==> Summary tab, the width and height are listed there.

Is there any way to retrieve the dimensions - which would be just as easy to work with?

Regards,

William

Link to comment
Share on other sites

Anything that shows in the _ArrayDisplay can be retrieved by this, if there isn't any information after the property then it can't.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks, BrewManNH.  Looks like the info is inaccessible for scripting, then.

I'll look into getting it from the irfanview command line - though a bit messier as this will only write the data to a file, as far as I can make out.  But it should be easy to read it back into autoit.

Regards,

William

Link to comment
Share on other sites

This seems to work for tif and jpeg files [change the extension in 2 places to switch between file types for this demo]

William

#Include <Array.au3>
#include <File.au3>
#Include <String.au3>
 
 
Global $sInImage= FileOpenDialog ("Test File","C:\Documents and Settings\Owner\Desktop\SBACC Comp nov2013\possibles","All(*.*)")
Global $Testfile = StringReplace ($sInImage,".tif",".txt")
RunWait (@ScriptDir&'\i_view32.exe "'& $sInImage & '" /info="'&$Testfile&'"','')
$file= FileOpen($Testfile)
$text = FileRead($file)
FileClose($file)
$adimensions = _StringBetween($text,"Image dimensions =","Pixels")
$aHtWid = StringSplit ($adimensions[0]," x ",1)
$wid = StringStripWS($aHtWid[1],8)
$ht = StringStripWS($aHtWid[2],8)
MsgBox (0,"Wid x Ht", $wid&"x"&$ht)
FileDelete ($Testfile)
exit
 
Edited by saywell
Link to comment
Share on other sites

  • 11 months later...

#include <File.au3> ; only used for the example script, not needed for the UDF
#include <Array.au3> ; only used for the example script, not needed for the UDF
#include <Constants.au3> ; only used for the MsgBox, not needed for the UDF
$sFolder = FileSelectFolder("Select a folder to scan", "")
$sFolder &= ""
$aFiles = _FileListToArray($sFolder, "*.exe")
For $I = 1 To $aFiles[0]
    $aDetails = _FileGetProperty($sFolder & "\" & $aFiles[$I]) ; Returns an array with all properties of the file
    _ArrayDisplay($aDetails)
Next
Global $sDetails = _FileGetProperty($sFolder & "\" & $aFiles[$aFiles[0]], "date modified")
MsgBox($MB_SYSTEMMODAL, "Date Modified", $sDetails)

Just a suggestion: To avoid the example giving a "Subscript used on non-accessible variable" error if the scanned folder if $aFiles = 0, perhaps add something like this before the For loop:

If $aFiles = 0 Then

 MsgBox (0, "Error", "There were no *.exe files in folder")

 Exit

EndIf

 

(thanks for sharing)

Link to comment
Share on other sites

  • 2 months later...
  • 2 years later...

@BrewManNH , I wanted to optimize the code and here it is:

#include <File.au3> ; only used for the example script, not needed for the UDF
#include <Array.au3> ; only used for the example script, not needed for the UDF
#include <Constants.au3> ; only used for the MsgBox, not needed for the UDF

example()
Func example()
    Local $n, $t, $aDetails
    For $n = 1 To 10
        $t = TimerInit()
        $aDetails = _FileGetProperty(@ScriptFullPath, 11)
        ConsoleWrite(Round(TimerDiff($t), 3) & @TAB & $aDetails & @CRLF)
    Next
    ConsoleWrite(@CRLF)
    For $n = 1 To 10 ; shows the optimization, repeatedly getting a property by name
        $t = TimerInit()
        $aDetails = _FileGetProperty(@ScriptFullPath, "Owner")
        ConsoleWrite(Round(TimerDiff($t), 3) & @TAB & $aDetails & @CRLF)
    Next
    ConsoleWrite(@CRLF)

    $t = TimerInit()
    $aDetails = _FileGetProperty(StringLeft(@WindowsDir, 2)) ; Returns an array with all properties of the file
    ConsoleWrite(Round(TimerDiff($t), 3) & ' - Drive properties' & @CRLF)
    _ArrayDisplay($aDetails, "Drive properties")

    $t = TimerInit()
    $aDetails = _FileGetProperty(@ScriptFullPath) ; Returns an array with all properties of the file
    ConsoleWrite(Round(TimerDiff($t), 3) & ' - file properties' & @CRLF)
    _ArrayDisplay($aDetails, "file properties")

    $t = TimerInit()
    $aDetails = _FileGetProperty(@ScriptDir) ; Returns an array with all properties of the file
    ConsoleWrite(Round(TimerDiff($t), 3) & ' - folder properties' & @CRLF)
    _ArrayDisplay($aDetails, "folder properties")

    $t = TimerInit()
    $sDetails = _FileGetProperty(@ScriptFullPath, "date modified")
    ConsoleWrite(Round(TimerDiff($t), 3) & " - date modified" & @CRLF)
    MsgBox($MB_SYSTEMMODAL, "Date Modified", $sDetails)

    Exit 0 ;
EndFunc   ;==>example

;===============================================================================
; Function Name.....: _FileGetProperty ; https://www.autoitscript.com/forum/topic/148232-_filegetproperty-retrieves-the-properties-of-a-file/
; Description.......: Returns a property, or all properties, for a file.
; Version...........: 1.0.3
; Change Date.......: 09-03-2017
; AutoIt Version....: 3.3.14.x (due to the use of Static, but it could be a Global and use 3.2.12.x)
; Parameter(s)......: $FGP_Path - String containing the file path to return the property from.
;                     $FGP_PROPERTY - [optional] String containing the name of the property to return. (default = "")
;                     $iPropertyCount - [optional] The number of properties to search through for $FGP_PROPERTY, or the number of items
;                                       returned in the array if $FGP_PROPERTY is blank. (default = 300)
; Requirements(s)...: None
; Return Value(s)...: Success: Returns a string containing the property value.
;                     If $FGP_PROPERTY is blank, a two-dimensional array is returned:
;                         $av_array[0][0] = Number of properties.
;                         $av_array[1][0] = 1st property name.
;                         $as_array[1][1] = 1st property value.
;                         $av_array[n][0] = nth property name.
;                         $as_array[n][1] = nth property value.
;                     Failure: Returns an empty string and sets @error to:
;                       1 = The folder $FGP_Path does not exist.
;                       2 = The property $FGP_PROPERTY does not exist or the array could not be created.
;                       3 = Unable to create the "Shell.Application" object $objShell.
; Author(s).........: - Simucal <Simucal@gmail.com>
;                     - Modified by: Sean Hart <autoit@hartmail.ca>
;                     - Modified by: teh_hahn <sPiTsHiT@gmx.de>
;                     - Modified by: BrewManNH
;                     - Modified by: argumentum ; added some optimization
; URL...............: http://www.autoitscript.com/forum/topic/34732-udf-getfileproperty/page__view__findpost__p__557571
; Note(s)...........: Modified the script that teh_hahn posted at the above link to include the properties that
;                     Vista and Win 7 include that Windows XP doesn't. Also removed the ReDims for the $av_ret array and
;                     replaced it with a single ReDim after it has found all the properties, this should speed things up.
;                     I further updated the code so there's a single point of return except for any errors encountered.
;                     $iPropertyCount is now a function parameter instead of being hardcoded in the function itself.
;                     Added the use of $FGP_PROPERTY as Index + 1 ( as is shown the array ), in additon to $FGP_PROPERTY as Verb
;                     Added the array Index to the @extended, as this the optimization is for just te last index used.
;===============================================================================
Func _FileGetProperty($FGP_Path, $FGP_PROPERTY = "", $iPropertyCount = 300)
    If $FGP_PROPERTY = Default Then $FGP_PROPERTY = ""
    $FGP_Path = StringRegExpReplace($FGP_Path, '["'']', "") ; strip the quotes, if any from the incoming string
    If Not FileExists($FGP_Path) Then Return SetError(1, 0, "") ; path not found
    Local Const $objShell = ObjCreate("Shell.Application")
    If @error Then Return SetError(3, 0, "")
    Local Const $FGP_File = StringTrimLeft($FGP_Path, StringInStr($FGP_Path, "\", 0, -1))
    Local Const $FGP_Dir = StringTrimRight($FGP_Path, StringLen($FGP_File) + 1)
    Local Const $objFolder = $objShell.NameSpace($FGP_Dir)
    Local Const $objFolderItem = $objFolder.Parsename($FGP_File)
    Local $Return = "", $iError = 0, $iExtended = 0
    Local Static $FGP_PROPERTY_Text = "", $FGP_PROPERTY_Index = 0
    If $FGP_PROPERTY_Text = $FGP_PROPERTY And $FGP_PROPERTY_Index Then
        If $objFolder.GetDetailsOf($objFolder.Items, $FGP_PROPERTY_Index) = $FGP_PROPERTY Then
            Return SetError(0, $FGP_PROPERTY_Index, $objFolder.GetDetailsOf($objFolderItem, $FGP_PROPERTY_Index))
        EndIf
    EndIf
    If Int($FGP_PROPERTY) Then
        $Return = $objFolder.GetDetailsOf($objFolderItem, $FGP_PROPERTY - 1)
        If $Return = "" Then
            $iError = 2
        EndIf
    ElseIf $FGP_PROPERTY Then
        For $I = 0 To $iPropertyCount
            If $objFolder.GetDetailsOf($objFolder.Items, $I) = $FGP_PROPERTY Then
                $FGP_PROPERTY_Text = $FGP_PROPERTY
                $FGP_PROPERTY_Index = $I
                $iExtended = $I
                $Return = $objFolder.GetDetailsOf($objFolderItem, $I)
            EndIf
        Next
        If $Return = "" Then
            $iError = 2
        EndIf
    Else
        Local $av_ret[$iPropertyCount + 1][2] = [[0]]
        For $I = 1 To $iPropertyCount
            If $objFolder.GetDetailsOf($objFolder.Items, $I) Then
                $av_ret[$I][0] = $objFolder.GetDetailsOf($objFolder.Items, $I - 1)
                $av_ret[$I][1] = $objFolder.GetDetailsOf($objFolderItem, $I - 1)
                $av_ret[0][0] += 1
            EndIf
        Next
        ReDim $av_ret[$av_ret[0][0] + 1][2]
        If Not $av_ret[1][0] Then
            $iError = 2
            $av_ret = $Return
        Else
            $Return = $av_ret
        EndIf
    EndIf
    Return SetError($iError, $iExtended, $Return)
EndFunc   ;==>_FileGetProperty

Thanks for sharing

Edit on 09-03-2017: Added the index value to the @Extended

Edited by argumentum
fix the code

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • 2 months later...

Trying to get the height and width from an .mp4 file, but i can't. Any idea why?

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

9 hours ago, careca said:

Trying to get the height and width from an .mp4 file, but i can't. Any idea why?

ConsoleWrite( _FileGetProperty("my.mp4","Frame height") & @CRLF)
ConsoleWrite( _FileGetProperty("my.mp4","Frame width") & @CRLF)

That did it for me.

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...