UDF - _FileGetProperty

  • Hi,

    hiermit präsentiere ich Euch die UDF _FileGetProperty. Konnte ich bereits sehr gut gebrauchen. Siehe dazu auch: http://www.autoitscript.com/forum/index.php?showtopic=34732

    Spoiler anzeigen
    [autoit]

    ;===============================================================================
    ; 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 or folder 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 <[email='Simucal@gmail.com'][/email]>
    ; - Modified by: Sean Hart <[email='autoit@hartmail.ca'][/email]>
    ; - Modified by: teh_hahn <[email='sPiTsHiT@gmx.de'][/email]>
    ; 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)

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    Return $av_ret
    EndFunc ;==>_FileGetProperty

    [/autoit]

    2 Mal editiert, zuletzt von teh_hahn (29. Juli 2008 um 09:40)