Jump to content

FileSetTime issue


orbs
 Share

Recommended Posts

i stumbles upon a bizarre behavior of FileSetTime. in brief, the issue is that after setting the time for a file, it is reported differently in DOS command prompt and in Windows Explorer. DOS reports the correct time, and so does FileGetTime; but Windows Explorer reports incorrect time - 1 hour earlier (i'm currently on time zone GMT+2, with DST of +1 hour).

 consider this very simple reproducer:

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

Global $sFile='C:\TEMP\file1.txt'
ConsoleWrite(@CRLF)
ConsoleWrite('>this is just making sure the file was created successfully:' & @CRLF)
Global $hFile=FileOpen($sFile,2+8)
ConsoleWrite('FileOpen = '&$hFile & @CRLF)
ConsoleWrite('FileWrite = '&FileWrite($hFile,'this is some text') & @CRLF)
ConsoleWrite('FileClose = '&FileClose($hFile) & @CRLF)
ConsoleWrite('FileGetSize = '&FileGetSize($sFile) & @CRLF)
ConsoleWrite('>set and verify the file time:' & @CRLF)
ConsoleWrite('FileSetTime = '&FileSetTime($sFile,'20011231010203') & @CRLF)
ConsoleWrite('FileGetTime = '&FileGetTime($sFile,0,1) & @CRLF)
ConsoleWrite('! now go and check the file time in Windows Explorer and in DOS command prompt.' & @CRLF)
ConsoleWrite(@CRLF)

SciTE output: (correct)

FileSetTime_-_img1_-_SciTE.thumb.png.22b

DOS dir output (correct, although not showing seconds):

FileSetTime_-_img2_-_DOS_command_prompt.

Windows Explorer file properties dialog (incorrect - should be 01:02:03 instead of 00:02:03):

FileSetTime_-_img3_-_Windows_Explorer_Pr

i checked all 3 timestamps (Created/Modified/Accessed) - same issue.

checked various past times, with and without DST, also future times - same issue.

using Windows 7 x64 + AutoIt 3.3.14.2. also tested on Windows XP + AutoIt v3,3.8.1 and did not observe the issue there (both systems are properly configured with time zone and DST).

AutoIt full change log does not mention FileSetTime recently.

to be honest, i do not think it is AutoIt to blame; most likely it's a bad combination of Windows and my time zone and DST. but if anyone can make any sense of it, it's probably the AutoIt community... :)

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

Windows Explorer uses UTC times for NTFS file systems and then takes into account your time zone settings. On my computer the console window shows one file with the correct date, but one hour off than the Windows Explorer show. One shows 11:04 am, the other 10:04 am.  This is because when it was created (November) the DST setting wasn't in effect, but currently it is. I also have a file that was created in September that has the same time values, because they were both created in the same time zone setting, next month when DST ends I'm sure that this file will have a different time stamp in Windows Explorer again.

This has nothing to do with AutoIt it is just an idiosyncrasy in Windows.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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