Jump to content

FileSetTime is not working correctly for me


Recommended Posts

I'm grabbing the name of a file, which is the date and time, and setting it to the modified date. The problem is it is the date gets set properly but the time doesn't...it's off by -1hr, and I'm verifying it beforehand.

The input format varies as 2022-02-02_083224_P.jpg ----- YYYY-MM-DD_HHMMSS

 

Func _Set_File_Dates($sFileSelect)

    $aDirContent_New = StringSplit($sFileSelect, "|", 2)

    For $i = UBound($aDirContent_New) - 1 to 0 Step - 1

        $FileNameDate = StringSplit($aDirContent_New[$i], "\", 2)

        $aFileNameDate = StringSplit($FileNameDate[UBound($FileNameDate)-1], "_", 2)

        $NewTime = $aFileNameDate[0] & $aFileNameDate[1]

        $NewTime = StringRegExp($NewTime, "\d+", 3)

        _ArrayDisplay($NewTime)

        $NewTime = $NewTime[0] & $NewTime[1] & $NewTime[2]

        MsgBox(0,"new date", $NewTime)

        FileSetTime ( $aDirContent_New[$i], $NewTime, $FT_MODIFIED)

    Next
;Exit
EndFunc

Any help?

Edited by Champak
Link to comment
Share on other sites

 

;#include <Array.au3>
#include <FileConstants.au3>

;~  The input format varies as 2022-02-02_083224_P.jpg ----- YYYY-MM-DD_HHMMSS

$sFileSelect = @ScriptDir & "\2022-02-02_083225_R.jpg|" & @ScriptDir & "\2022-03-02_083224_P.jpg"

_Set_File_Dates($sFileSelect)


Func _Set_File_Dates($sFileSelect)

    $aDirContent_New = StringSplit($sFileSelect, "|", 2)

    For $i = UBound($aDirContent_New) - 1 To 0 Step -1

        $FileNameDate = StringSplit($aDirContent_New[$i], "\", 2)
        ConsoleWrite("File=" & $aDirContent_New[$i] & @CRLF)

        $aFileNameDate = StringSplit($FileNameDate[UBound($FileNameDate) - 1], "_", 2)
        ConsoleWrite("$aFileNameDate[0]=" & $aFileNameDate[0] & @CRLF)
        ConsoleWrite("$aFileNameDate[1]=" & $aFileNameDate[1] & @CRLF)

        $NewDate = StringReplace($aFileNameDate[0], "-", "")
        ConsoleWrite("$NewDate=" & $NewDate & @CRLF)

        $Hour = StringLeft($aFileNameDate[1], 2)
        $Minute = StringMid($aFileNameDate[1], 3, 2)
        $Second = StringRight($aFileNameDate[1], 2)

        ; Adjust DST hour
        $Hour = StringFormat("%02i", Number($Hour) + 1)

        ; Combine date and time in the format "YYYYMMDDHHMMSS"
        $FinalDateTime = $NewDate & $Hour & $Minute & $Second
        ConsoleWrite("$FinalDateTime:" & $FinalDateTime & @CRLF)

        ConsoleWrite("FileSetTime=" & FileSetTime($aDirContent_New[$i], $FinalDateTime, $FT_MODIFIED) & @CRLF)
        ConsoleWrite("" & @CRLF)

    Next
    ;Exit
EndFunc   ;==>_Set_File_Dates

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

thanks for the suggestion
It is also quite problematic since it cannot understand whether the entered date is summer or winter time.
I thought that I would manage it with a small correction, but it was not so simple since the DST date is not fixed and every year is different.

so the best solution (easiest) is the one he indicated pixelsearch  in the link

I know that I know nothing

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