#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 #include #include #include #include ConsoleWrite("Set Modified datetime of this script to Jan 12th 2016 at 15:16:17" & @CRLF) FileSetTimeExt(@ScriptFullPath, "20160123151617", 0, 0) Func FileSetTimeExt($filename, $time, $type = 0, $recurse = 0) ; v1.0 ; Extended FileSetTime function to properly deal with DST (Daylight Saving Time (summertime/wintertime)) on Windows 7+ ; Usage is identical to the FileSetTime function with full wildcard support, including multiple * and ? usage. ; ; AutoIt Version: 3.3.14.2 ; This function requires Windows 7 or later. ; ; Requirements to include in your main program: ; #include ; #include ; #include ; #include If $type = Default Then $type = 0 If $recurse = Default Then $recurse = 0 If $time = "" Then $time = StringRegExpReplace(_NowCalc(), "[^0-9]", "") Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "", $ssDir = "", $sDummy1 = "", $sDummy2 = "" _PathSplit($filename, $sDrive, $sDir, $sFileName, $sExtension) ; extend path to full path if filename has no path or a path relative to ScriptDir If $sDrive = "" Then _PathSplit(@ScriptFullPath, $sDrive, $ssDir, $sDummy1, $sDummy2) $sDir = $ssDir & $sDir $filename = _PathMake($sDrive, $sDir, $sFileName, $sExtension) EndIf ; FileSetTime makes no difference between * and *.*, whereas_WinAPI_IsNameInExpression does, so make adjustments If $sExtension = ".*" Then $sFileName = $sFileName & "*" $sExtension = "" EndIf Local $hSearch $hSearch = FileFindFirstFile(_PathMake($sDrive, $sDir, "*", ".*")) ; searches for every file and directory If $hSearch = -1 Then Return 1 Local $pattern, $eExt, $tSystem, $tFile, $hFile, $pFileName ; get correct local time $tSystem = _Date_Time_EncodeSystemTime(StringMid($time, 5, 2), StringMid($time, 7, 2), StringLeft($time, 4), _ StringMid($time, 9, 2), StringMid($time, 11, 2), StringMid($time, 13, 2)) $tSystem = _Date_Time_TzSpecificLocalTimeToSystemTime($tSystem) $tFile = _Date_Time_SystemTimeToFileTime($tSystem) $pattern = StringMid(_PathMake("", "", $sFileName, $sExtension), 2) ; StringMid skips leading \ While 1 $sFileName = FileFindNextFile($hSearch) If @error = 1 Then ; no more files or directories match the pattern ExitLoop Else $eExt = @extended $pFileName = _PathMake($sDrive, $sDir, $sFileName, "") ; _WinAPI_IsNameInExpression supports full wildcard matching, including multiple * and ? usage. If _WinAPI_IsNameInExpression($sFileName, $pattern) Then ; set correct local time for matching file or directory ; try the usual function first to catch errors beforehand If FileSetTime($pFileName, $time, $type) = 0 Then FileClose($hSearch) Return 0 ; abort on error EndIf ; use _WinAPI_CreateFileEx instead of _WinAPI_CreateFile to include directory renaming without an 'Access is denied' error $hFile = _WinAPI_CreateFileEx($pFileName, $OPEN_EXISTING, $GENERIC_WRITE, $FILE_SHARE_WRITE, $FILE_FLAG_BACKUP_SEMANTICS) Switch $type Case 0 _Date_Time_SetFileTime($hFile, 0, 0, $tFile) ; set time Last modified (= Last written) (default) Case 1 _Date_Time_SetFileTime($hFile, $tFile, 0, 0) ; set time Created Case 2 _Date_Time_SetFileTime($hFile, 0, $tFile, 0) ; set time Last accessed EndSwitch _WinAPI_CloseHandle($hFile) EndIf ; perform a full recursive search if need be If $eExt = 1 And $recurse = 1 Then If FileSetTimeExt($pFileName & '\' & $pattern, $time, $type, $recurse) = 0 Then FileClose($hSearch) Return 0 ; abort on error EndIf EndIf EndIf WEnd FileClose($hSearch) Return 1 ; no error occurred EndFunc ;==>FileSetTimeExt