Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Reset Created/Accessed/Modified attribute


  • Please log in to reply
1 reply to this topic
IconBoy
  • Validating
  • 108 posts
  • Last active: Feb 08 2018 01:15 AM
  • Joined: 24 Feb 2006
I have four or so files that I would like to "reset" their Created, Modified, Accessed attributes to a specific date and time once those specific files (in certain directories) are opened/used/accessed etc.
Is there a way to do this with AHK so that it monitors these files and once "finished with" the C/M/A attributes can be applied to. E.g.:

My Documents\Test\file1.txt
My Documents\Test\file2.doc
My Documents\Test\file3.gif
These 3 files were all created on 25 Sep 2004 at 13:00:00

If I were to open any or all of the above listed files today, I want AHK to reset the attributes to 25 Sep 2004 at 13:00:00.
Anyone help me out please?
Thanks very much.

wOxxOm
  • Members
  • 371 posts
  • Last active: Feb 20 2015 12:10 PM
  • Joined: 09 Feb 2006
getFileTimes(file,byref ftCreate,byref ftAccess,byref ftModify)
{
   hFile:=dllCall("CreateFileA", "str",file, "uint",0x80000000, "uint",1|2, "uint",0, "uint",3, "uint",0, "uint",0)
   ifEqual,hFile,-1, return
   dllCall("GetFileTime", "uint",hFile, "int64p",ftCreate, "int64p",ftAccess, "int64p",ftModify)
   dllCall("CloseHandle", "uint",hFile)
   return true
}

setFileTimes(file, ftCreate, ftAccess, ftModify)
{
   hFile:=dllCall("CreateFileA", "str",file, "uint",0xC0000000, "uint",1|2, "uint",0, "uint",3, "uint",0, "uint",0)
   ifEqual,hFile,-1, return
   dllCall("SetFileTime", "uint",hFile, "int64p",ftCreate, "int64p",ftAccess, "int64p",ftModify)
   dllCall("CloseHandle", "uint",hFile)
   return true
}

usage:
file=D:\someFolder\someFile.txt
getFileTimes(file,ftC,ftA,ftM)

;processing
Fileappend,HEYHO!!!!,%file%
;.....................
;.....................

setFileTimes(file,ftC,ftA,ftM)