Sign in to follow this  
Followers 0
seanhart

UDF GetFileProperty

11 posts in this topic

I just wrote the attached UDF to solve a need I had to be able to return the property of a file given the property name.

If a property name is not specified or blank, a 2 dimensional array is returned listing all valid properties and their values.

Some examples:

$bitrate = _GetFileProperty("C:\WINDOWS\clock.avi", "Bit Rate") ;gives "00:00:12"

$size = _GetFileProperty("C:\WINDOWS\Gone Fishing.bmp", "Dimensions") ;gives "128 x 128"

$company = _GetFileProperty("C:\WINDOWS\Notepad.exe", "Company") ;gives "Microsoft Corporation"

$all_props = _GetFileProperty("C:\WINDOWS\Notepad.exe")

; $all_props[3][1] = "Type"

; $all_props[3][2] = "Application"

Enjoy!

GetFileProperty.au3

Share this post


Link to post
Share on other sites



It's similar but a little more user friendly and robust. Using Simucal's UDF on my system gave the wrong results (for example my Company property was at index 33 instead of 30). My script pulls the property names directly from the directory object and doesn't rely on the index numbers. The property names also match with what you would see in explorer or other apps, thus it's easier to plug them in to the function instead of looking up the index number.

I gave Simucal credit in my UDF for inspiring it though.

Share this post


Link to post
Share on other sites

CODE
$file_name = _GetFileProperty("C:\WINDOWS\Notepad.exe","Original File Name")

I tried to retrieve the Original File name property, but it returned a 0. Could you tell me what I did wrong?

Share this post


Link to post
Share on other sites

CODE
$file_name = _GetFileProperty("C:\WINDOWS\Notepad.exe","Original File Name")

I tried to retrieve the Original File name property, but it returned a 0. Could you tell me what I did wrong?

Nevermind! I found the answer....It pays to RTFM! :P

FileGetVersion("c:\windows\notepad.exe","OriginalFilename")

Share this post


Link to post
Share on other sites

Hi seanhart

Thanks for this it has been very useful however i can not get this to work with winpe2.0. Do you know what dll's it requires or is there another way to do this using the autoit defaults (what in the autoit helpfile).

Share this post


Link to post
Share on other sites

Hi,

any reason why you did $aProps[1][3] instead of $aProps[1][2] ?

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Hi,

I think this UDF is very useful, but there were a few glitches within the code. I fixed them and this is the result:

;===============================================================================
; Function Name.....: _FileGetProperty
; Description.......: Returns a property or all properties for a file.
; Version...........: 1.0.2
; Change Date.......: 2008-07-28
; AutoIt Version....: 3.2.12.1
;
; Parameter(s)......: $S_PATH - String containing the file path to return the property from.
;                     $S_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 $S_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 0 and sets @error to:
;                       1 = The folder $S_PATH does not exist.
;                       2 = The property $S_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>
; Company...........: None
; URL...............: None
; Note(s)...........: None
;===============================================================================
Func _FileGetProperty(Const $S_PATH, Const $S_PROPERTY = "")
    If Not FileExists($S_PATH) Then Return SetError(1, 0, 0)

    Local Const $S_FILE = StringTrimLeft($S_PATH, StringInStr($S_PATH, "\", 0, -1))
    Local Const $S_DIR = StringTrimRight($S_PATH, StringLen($S_FILE) + 1)

    Local Const $objShell = ObjCreate("Shell.Application")
    If @error Then Return SetError(3, 0, 0)

    Local Const $objFolder = $objShell.NameSpace($S_DIR)
    Local Const $objFolderItem = $objFolder.Parsename($S_FILE)

    If $S_PROPERTY Then
        For $i = 0 To 99
            If $objFolder.GetDetailsOf($objFolder.Items, $i) = $S_PROPERTY Then Return $objFolder.GetDetailsOf($objFolderItem, $i)
        Next
        Return SetError(2, 0, 0)
    EndIf

    Local $av_ret[1][2] = [[1]]
    For $i = 0 To 99
        If $objFolder.GetDetailsOf($objFolder.Items, $i) Then
            ReDim $av_ret[$av_ret[0][0] + 1][2]
            $av_ret[$av_ret[0][0]][0] = $objFolder.GetDetailsOf($objFolder.Items, $i)
            $av_ret[$av_ret[0][0]][1] = $objFolder.GetDetailsOf($objFolderItem, $i)
            $av_ret[0][0] += 1
        EndIf
    Next

    If Not $av_ret[1][0] Then Return SetError(2, 0, 0)
    $av_ret[0][0] -= 1

    Return $av_ret
EndFunc  ;==>_FileGetProperty

Share this post


Link to post
Share on other sites

I note that there are 267 extended file properties in Vista.

The idea of freeing the user from dependencies on the index number is a very good one, unfortunately I have discovered that even the property name can change between operating systems. A good example and the one that affected my code: Duration is called Length in Vista, and of course the index is different.

I see the possibility of expanding this UDF to provide a truly operating system independent (from the user's perspective) interface to extended file properties.

Share this post


Link to post
Share on other sites

Can't find the property "Last Saved By" in the array returned from the function. Any clues?

Share this post


Link to post
Share on other sites

Did you not know about BrewManNH's function? Look in their signature.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
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
Sign in to follow this  
Followers 0