Jump to content

[SOLVED] FileSetTime for Image! How ?


Trong
 Share

Recommended Posts

User gcue had a similar problem a few days ago and found a solution. Search the forum and you will know what I mean.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

Thanks!

#include <array.au3>
#include <GDIPlus.au3>
#include <file.au3>

$msg_normal = 0

Global Const $PropertyTagTypeByte = 1
Global Const $PropertyTagTypeASCII = 2
Global Const $PropertyTagTypeShort = 3
Global Const $PropertyTagTypeLong = 4
Global Const $PropertyTagTypeRational = 5
Global Const $PropertyTagTypeUndefined = 7
Global Const $PropertyTagTypeSLong = 9
Global Const $PropertyTagTypeSRational = 10

_GDIPlus_Startup()


$dir = "C:\Users\Me\Desktop\Halloween"
$date_time = "2015:10:29 09:00:00"

$array = _FileListToArrayRec($dir, "*.jpg", $FLTAR_FILES, 1, $FLTAR_SORT, $FLTAR_FULLPATH)

For $x = 1 To UBound($array) - 1
    $original_file = $array[$x]

    $file_name_extension = StringRegExpReplace($original_file, "^.*\\", "")
    $file_path_dir = StringReplace($original_file, "\" & $file_name_extension, "")
    $file_name = _GetFileName($original_file)
    $file_extension = _GetFileExtension($file_name_extension)

    $temp_file = $file_path_dir & "\" & $file_name & "_TMP." & $file_extension

    $hFile = _GDIPlus_ImageLoadFromFile($original_file)

    _GDIPlus_SetMetaData($hFile, "DateTimeOriginal", $date_time)

    _GDIPlus_ImageSaveToFile($hFile, $temp_file)

    _GDIPlus_ImageDispose($hFile)

    FileMove($temp_file, $original_file, 1)
Next

_GDIPlus_Shutdown()

Func _GDIPlus_SetMetaData($hHandle, $sTagName, $vStr)

    Local $tagPropertyItem = "ulong id; ulong length; ushort Type; ptr value"
    Local $Struct_String, $Struct_Meta, $aResult, $PropertyTagType

    Switch $sTagName
        Case "ImageWidth"
            $ID = 0x100
            $PropertyTagType = $PropertyTagTypeShort

        Case "ImageLength"
            $ID = 0x101
            $PropertyTagType = $PropertyTagTypeShort

        Case "BitsPerSample"
            $ID = 0x102
            $PropertyTagType = $PropertyTagTypeShort

        Case "Compression"
            $ID = 0x103
            $PropertyTagType = $PropertyTagTypeShort

        Case "PhotometricInterpretation"
            $ID = 0x106
            $PropertyTagType = $PropertyTagTypeShort

        Case "Orientation"
            $ID = 0x112
            $PropertyTagType = $PropertyTagTypeShort

        Case "SamplesPerPixel"
            $ID = 0x115
            $PropertyTagType = $PropertyTagTypeShort

        Case "PlanarConfiguration"
            $ID = 0x11C
            $PropertyTagType = $PropertyTagTypeShort

        Case "YCbCrSubSampling"
            $ID = 0x212
            $PropertyTagType = $PropertyTagTypeShort

        Case "YCbCrPositioning"
            $ID = 0x213
            $PropertyTagType = $PropertyTagTypeShort

        Case "XResolution"
            $ID = 0x11A
            $PropertyTagType = $PropertyTagTypeRational

        Case "YResolution"
            $ID = 0x11B
            $PropertyTagType = $PropertyTagTypeRational

        Case "ResolutionUnit"
            $ID = 0x296
            $PropertyTagType = $PropertyTagTypeShort

        Case "StripOffsets"
            $ID = 0x111
            $PropertyTagType = $PropertyTagTypeShort

        Case "RowsPerStrip"
            $ID = 0x116
            $PropertyTagType = $PropertyTagTypeShort

        Case "StripByteCounts"
            $ID = 0x117
            $PropertyTagType = $PropertyTagTypeShort

        Case "JPEGInterchangeFormat"
            $ID = 0x201
            $PropertyTagType = $PropertyTagTypeLong

        Case "JPEGInterchangeFormatLength"
            $ID = 0x202
            $PropertyTagType = $PropertyTagTypeLong

        Case "TransferFunction"
            $ID = 0x12D
            $PropertyTagType = $PropertyTagTypeShort

        Case "WhitePoint"
            $ID = 0x13E
            $PropertyTagType = $PropertyTagTypeRational

        Case "PrimaryChromaticities"
            $ID = 0x13F
            $PropertyTagType = $PropertyTagTypeRational

        Case "YCbCrCoefficients"
            $ID = 0x211
            $PropertyTagType = $PropertyTagTypeRational


        Case "ReferenceBlackWhite"
            $ID = 0x214
            $PropertyTagType = $PropertyTagTypeRational

        Case "DateTimeOriginal"
            $ID = 0x9003
            $PropertyTagType = $PropertyTagTypeASCII

        Case "DateTime"
            $ID = 0x132
            $PropertyTagType = $PropertyTagTypeASCII

        Case "ImageDescription"
            $ID = 0x10E
            $PropertyTagType = $PropertyTagTypeASCII

        Case "Make"
            $ID = 0x10F
            $PropertyTagType = $PropertyTagTypeASCII

        Case "Model"
            $ID = 0x110
            $PropertyTagType = $PropertyTagTypeASCII

        Case "Software"
            $ID = 0x131
            $PropertyTagType = $PropertyTagTypeASCII

        Case "Artist", "Author"
            $ID = 0x13B
            $PropertyTagType = $PropertyTagTypeASCII

        Case "Copyright"
            $ID = 0x8298
            $PropertyTagType = $PropertyTagTypeASCII

        Case Else
            Return SetError(1, -1, False)
    EndSwitch

    ; Store string in array
    $Struct_String = DllStructCreate("char[" & StringLen($vStr) + 1 & "];")
    DllStructSetData($Struct_String, 1, $vStr)

    $Struct_Meta = DllStructCreate($tagPropertyItem)
    DllStructSetData($Struct_Meta, "ID", $ID)
    DllStructSetData($Struct_Meta, "Length", StringLen($vStr) + 1)
    DllStructSetData($Struct_Meta, "Type", $PropertyTagType)
    DllStructSetData($Struct_Meta, "Value", DllStructGetPtr($Struct_String))

    $aResult = DllCall($__g_hGDIPDll, "int", "GdipSetPropertyItem", "hwnd", $hHandle, "ptr", DllStructGetPtr($Struct_Meta))
    If @error Then Return SetError(@error, @extended, False)

    Return SetError($aResult[0], 0, $aResult[0] = 0)

EndFunc   ;==>_GDIPlus_SetMetaData

Func _GetFileName($sFile)

    $file_name_extension = StringRegExpReplace($sFile, "^.*\\", "")
    $file_extension = StringRegExpReplace($file_name_extension, "^.*\.", "")
    $file_name = StringReplace($file_name_extension, "." & $file_extension, "")

    Return $file_name

EndFunc   ;==>_GetFileName

Func _GetFileExtension($sFile)
    Return StringRegExpReplace($sFile, "^.*\.", "")
EndFunc   ;==>_GetFileExtension

Func Debug($variable1 = "", $variable2 = "", $variable3 = "", $variable4 = "")

;~  #include <array.au3>
;~  $msg_normal = 0

    If IsArray($variable1) Then
        _ArrayDisplay($variable1)
    Else
        If $variable2 <> "" Then
            $variable1 &= @CRLF & $variable2
        EndIf

        If $variable3 <> "" Then
            $variable1 &= @CRLF & $variable3
        EndIf

        If $variable4 <> "" Then
            $variable1 &= @CRLF & $variable4
        EndIf

        ClipPut($variable1)
        MsgBox($msg_normal, "Debug", $variable1)
    EndIf

EndFunc   ;==>Debug

 

Regards,
 

Link to comment
Share on other sites

That was easy, wasn't it :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

Note that you can simply select multiple files in explorer and all will be edited when you edit the details... But a script may be better if you are doing it a lot ;)

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...