Jump to content

Udf: Get Extended File Property


Simucal
 Share

Recommended Posts

I totally agree!!!

This is essential, you can use it for a million things, and it goes very well with the initial purpose of autoit as a macro and Windows automation language.

I am going to use it for some image processing to get the width and height, but i am sure it will also be useful in the future.

Thank you very much!

No problem. It doesnt even compare to how heavily I use the excelcom udf.. so :D

I'm going to have to review the requirements for sending in a UDF

EDIT: Also, for image processing.. if there are some more image properties you would need.. In posting an answer for someone else I found a dll/com object that can access a ton of them.

Edited by Simucal
AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

  • Replies 66
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

..

I'm going to have to review the requirements for sending in a UDF

..

Actually, my support is for the feature to be included with AutoIt as an instrinsic function (part of the language), rather than as a UDF.

:D

Link to comment
Share on other sites

  • 1 month later...

I must be missing something. I get an error of Unknown function name for:

$oShellApp = ObjCreate ("shell.application")

$oShellApp = ^ Error

Not sure why since the comments here show that it does work. What did I do wrong?

#include <extprop.au3>
$path = FileOpenDialog("Select a file to read attributes",@ScriptDir,"All (*.*)")
$prop = _GetExtProperty($path,21)
ConsoleWrite("Property #"&$i&": "&$prop&@CRLF)

I mean am I using the wrong version? Also how do you tell what version you have? I have V3 is all the folder says.

Edited by tazdev
Link to comment
Share on other sites

I have that already. What I did not have was it TURNED ON!!! LOL There is a lnk file that is in the program group for AutoItV3->beta that will switch you over to it. I love that second sample script. I know exactly what I am gonna use it for.

Link to comment
Share on other sites

Perfect! exactly what i needed for my script, very well done mate!

No problem! What is your script if I may ask?

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

Here are some interesting VBScripts dealing with file properties:

'Modify a File Property:
'Modifies the Category property included in the summary information properties for a document named C:\Scripts\Test.doc. 

Set objPropertyReader = CreateObject("DSOleFile.PropertyReader")
Set objDocument = objPropertyReader.GetDocumentProperties _
    ("C:\Scripts\Test.doc")

objdocument.Category = "Scripting Documents"

'Create a Custom file property 
'Adds a custom property (TestProperty, with a value of "Test") to the summary information properties for a document named C:\Scripts\Test.doc.

Set objPropertyReader = CreateObject("DSOleFile.PropertyReader")
Set objDocument = objPropertyReader.GetDocumentProperties _
    ("C:\Scripts\Test.doc")

Set colCustomProperties = objdocument.CustomProperties
errReturn = ColCustomProperties.Add("TestProperty", "Test")

'Modify a Custom file property:
'Modifies a custom property (TestProperty, setting the new value to "New value") found in the summary information properties for a document named C:\Scripts\Test.doc.

Set objPropertyReader = CreateObject("DSOleFile.PropertyReader")
Set objDocument = objPropertyReader.GetDocumentProperties _
    ("C:\Scripts\Test.doc")

Set colCustomProperties = objdocument.CustomProperties
For Each strProperty in colCustomProperties
    If strProperty.Name = "TestProperty" Then
        strProperty.Value = "New value"
    End If
Next

'Delete a Custom file property 
'Deletes a custom property (TestProperty) from the summary information properties for a document named C:\Scripts\Test.doc. 

Set objPropertyReader = CreateObject("DSOleFile.PropertyReader")
Set objDocument = objPropertyReader.GetDocumentProperties_
    ("C:\Scripts\Test.doc")
Set colCustomProperties = objdocument.CustomProperties

For Each strProperty in colCustomProperties
    If strProperty.Name = "TestProperty" Then
        strProperty.Remove()
    End If
Next

:"> Reference:http://www.activexperts.com/activmonitor/w...stems/#MDPI.htm

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

I must be missing something. I get an error of Unknown function name for:

$oShellApp = ObjCreate ("shell.application")

$oShellApp = ^ Error

I mean am I using the wrong version? Also how do you tell what version you have? I have V3 is all the folder says.

hi taz, it was returning a non existant value which through the error, the fix could be shorter though..

;===============================================================================
; Function Name:    GetExtProperty($sPath,$iProp)
; Description:      Returns an extended property of a given file.
; Parameter(s):     $sPath - The path to the file you are attempting to retrieve an extended property from.
;                   $iProp - The numerical value for the property you want returned. If $iProp is is set
;                             to -1 then all properties will be returned in a 1 dimensional array in their corresponding order.
;                           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 - The extended file property, or if $iProp = -1 then an array with all properties
;                   On Failure - 0, @Error - 1 (If file does not exist)
; Author(s):        Simucal (Simucal@gmail.com)
; Note(s):
;
;===============================================================================
Func _GetExtProperty($sPath, $iProp)
    Local $iExist, $sFile, $sDir, $oShellApp, $oDir, $oFile, $aProperty, $sProperty
    $iExist = FileExists($sPath)
    If $iExist = 0 Then
        SetError(1)
        Return 0
    Else
        If StringInStr($sPath, "\") <> 0 Then
            $sFile = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1))
            $sDir = StringTrimRight($sPath, (StringLen($sPath) - StringInStr($sPath, "\", 0, -1)))
        Else
            $sFile = $sPath
            $sDir = @ScriptDir
        EndIf
        $oShellApp = ObjCreate ("shell.application")
        $oDir = $oShellApp.NameSpace ($sDir)
        $oFile = $oDir.Parsename ($sFile)
        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)
            If $sProperty = "" Then
                Return 0
            Else
                Return $sProperty
            EndIf
        EndIf
    EndIf
EndFunc   ;==>_GetExtProperty
Edited by WTS
Link to comment
Share on other sites

:) I am also having the problem that tazdev was having... :)

$oShellApp = ObjCreate ("shell.application")

$oShellApp = ^ Error

And I see that people have replied giving him the answer...but I do not understand the answer...do I have to install a beta version of Autoit? Or were the VB scripts needed somewhere in my code?

:whistle:

Thanks

Link to comment
Share on other sites

:) I am also having the problem that tazdev was having... :)

And I see that people have replied giving him the answer...but I do not understand the answer...do I have to install a beta version of Autoit? Or were the VB scripts needed somewhere in my code?

:whistle:

Thanks

Yes you would need to install/run the beta version.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • 3 weeks later...

I'm using the latest 3.2 version and having problems with getting information about EXE files using this UDF, especially 32, 33, and 34 where those properties do exist.

Any body else having the same problems?

Link to comment
Share on other sites

  • 4 weeks later...

Can someone help me to translate this UDF to Visual Basic? My translated code:

Function _GetExtProperty(ByVal s_path, ByVal i_prop)
        s_file = s_path.TrimStart(InStr(s_path, "\", 0, -1))
        s_dir = s_path.TrimEnd((Len(s_path) - InStr(s_path, "\", 0, -1)))
        ShellApp = CreateObject("shell.application")
        oDir = ShellApp.NameSpace(s_dir)
        oFile = oDir.Parsename(s_file)
        property1 = oDir.GetDetailsOf(oFile, i_prop)
        If property1 = "" Then
            Return 0
        Else
            Return property1
        End If
    End Function

but it creates error...

Link to comment
Share on other sites

Is it possible to have it send the data to a list?

like this:

Name: name
Size = size
Type = type
DateModified = date
DateCreated = date

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

Is it possible to have it send the data to a list?

like this:

Name: name
Size = size
Type = type
DateModified = date
DateCreated = date
That's call FileWrite

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Wouldn't that just say [0]: name not Name: name ?

If so, that doesn't answer my question.

Edited by Firestorm

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

Wouldn't that just say [0]: name not Name: name ?

If so, that doesn't answer my question.

He gave you the info need to do what you want i.e.

#include <extprop.au3>
$path = FileOpenDialog("Select a file to read attributes",@ScriptDir,"All (*.*)")
FileWrite(@ScriptDir & "\FileInfo.txt", "Name: " & _GetExtProperty($path,0) & @CRLF)

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

you can get each seperately or get all the info and reference the parts of the array you need and write it to the screen, file etc...

#include <extprop.au3>
$path = FileOpenDialog("Select a file to read attributes",@ScriptDir,"All (*.*)")
MsgBox(0,$path, "Name: " & _GetExtProperty($path,0) & @CRLF & _
    "Size: " & _GetExtProperty($path,1) & @CRLF & _
    "Type: " & _GetExtProperty($path,2) & @CRLF & _
    "Date Modified: " & _GetExtProperty($path,3) & @CRLF & _
    "Date Created: " & _GetExtProperty($path,4))

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...