Page 1 sur 1
[R] Lire les propriétées d'un executable
Posté : mar. 07 août 2007 15:12
par XcessiV
Bonjour.
J'aimerai lire les propriétées d'un fichier pour pouvoir comparer les versions.
Est-ce possible ?
Cordialement, XcessiV
Posté : mar. 07 août 2007 21:18
par Tlem
Je l'avais déjà mis sur l'ancien forum, mais bon ...
► Afficher le textele code
Code : Tout sélectionner
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.2.4.9
Author: PsaltyDS
http://www.autoitscript.com/forum/index.php?showtopic=40684&view=findpost&p=334962
Script Function:
Template AutoIt script.
#ce ----------------------------------------------------------------------------
; Test the _FileGetExtProp() UDF
#include <array.au3>
While 1
; Get user selections to test
$path = FileOpenDialog("Select a file to read attributes", @ScriptDir, "All (*.*)")
If @error Then Exit
$prop = Number(InputBox("_FileGetExtProp()", "Enter property number (-1 thru 34): ", "-1"))
If @error Then Exit
; Test the function
$RET = _FileGetExtProp($path, $prop)
$ErrSav = @error
$ExtSav = @extended
; Present results
If IsArray($RET) Then
_ArrayDisplay($RET, "Property Array")
Else
MsgBox(64, "Property String", "File: " & $path & @CRLF & _
"Property[" & $prop & "] = " & $RET & @CRLF & _
"@error = " & $ErrSav & " @extended = " & $ExtSav)
EndIf
WEnd
;===============================================================================
; Function Name: _FileGetExtProp($sPath,$iProp)
; Description: Returns extended properties of a given file.
; Parameter(s): $sPath = The file from which to retrieve an extended property.
; Does not have to be fully pathed out, and can use realative path
; from @WorkingDir; i.e. "File.txt", or "..\File.txt".
; $iProp = The integer value for the property to return.
; $iProp = -1 (the default) returns all properties in a 0-based array.
; The properties are as follows:
; Name = 0
; Size = 1
; Type = 2
; DateModified = 3
; DateCreated = 4
; DateAccessed = 5
; Attributes = 6
; Status = 7
; Owner = 8
; Author = 9
; Title = 10
; Subject = 11
; Category = 12
; Pages = 13
; Comments = 14
; Copyright = 15
; Artist = 16
; AlbumTitle = 17
; Year = 18
; TrackNumber = 19
; Genre = 20
; Duration = 21
; BitRate = 22
; Protected = 23
; CameraModel = 24
; DatePictureTaken = 25
; Dimensions = 26
; Width = 27
; Height = 28
; Company = 30
; Description = 31
; FileVersion = 32
; ProductName = 33
; ProductVersion = 34
; Requirement(s): File specified in $spath must exist.
; Return Value(s): On Success returns 0-based array of properties, or string specified by $iProp.
; On Failure sets @error and @extended (see code below for details)
; @error = 1 for bad parameter, 2 for object reference failure
; Note: Will return "" for an unset property (no error).
; Author(s): Simucal (Simucal@gmail.com)
; Modified version by PsaltyDS at http://www.autoitscript.com/forum
; Note(s):
; 2007-04-27 Modified by PsaltyDS from Simucal's original function:
; Changed function name from _GetExtProperty to _FileGetExtProp, to group it by
; naming convention with the other _File* UDFs.
; Made optional $iProp = -1 default.
; Changed to allow $sPath without full path.
; Changed to not report empty fields as errors, returns "".
; Added more detailed @error and @extended on failure.
;===============================================================================
Func _FileGetExtProp($sPath, $iProp = -1)
Local $iExist, $sFile, $sDir, $oShellApp, $oDir, $oFile, $aProperty, $sProperty
If FileExists($sPath) Then
$sPath = FileGetShortName($sPath, 1)
If IsInt($iProp) And $iProp >= -1 And $iProp <= 34 Then
$sFile = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1))
$sDir = StringTrimRight($sPath, (StringLen($sPath) - StringInStr($sPath, "\", 0, -1)))
$oShellApp = ObjCreate("shell.application")
If IsObj($oShellApp) Then
$oDir = $oShellApp.NameSpace ($sDir)
If IsObj($oDir) Then
$oFile = $oDir.Parsename ($sFile)
If IsObj($oFile) Then
If $iProp = -1 Then
Local $aProperty[35]
For $i = 0 To 34
$aProperty[$i] = $oDir.GetDetailsOf ($oFile, $i)
Next
Return $aProperty
Else
$sProperty = $oDir.GetDetailsOf ($oFile, $iProp)
Return $sProperty
EndIf
Else
Return SetError(2, 2, 0) ; Failed to get file object
EndIf
Else
Return SetError(2, 1, 0) ; Failed to get directory object
EndIf
Else
Return SetError(2, 0, 0) ; Failed to create shell app
EndIf
Else
Return SetError(1, 1, 0) ; $iProp is not integer, or out of range
EndIf
Else
Return SetError(1, 0, 0) ; file does not exist
EndIf
EndFunc ;==>_FileGetExtProp