Hello
this is a program that allows you to set the date and time of a specified file
just place in any txt file called "myfile.txt" in the same folder as the compile program Set_FileTime.exe
and run this exe, it will reset the date to Apr 18 2018 and time 6:55 pm
if you find any problem with this code please feel free to modify it and let us know about it. Thanxx
' Set_FileTime.o2bas
' Set the time and date of a file
$ filename "Set_FileTime.exe"
uses RTL64
uses corewin
uses Timeutil
' https://msdn.microsoft.com/en-us/library/windows/desktop/aa365282(v=vs.85).aspx
typedef struct _OFSTRUCT {
BYTE cBytes;
BYTE fFixedDisk;
WORD nErrCode;
WORD Reserved1;
WORD Reserved2;
CHAR szPathName[OFS_MAXPATHNAME];
} OFSTRUCT, *POFSTRUCT;
'=====================================================
' SetFileDate - Set the time and date of a file
'
SUB SetFileDate(sFileName AS STRING, _
iYear AS LONG, iMonth AS LONG, iDay AS LONG, _
iHour AS LONG, iMinute AS LONG, iSecond AS LONG) EXPORT
LOCAL hFile AS sys
LOCAL CreationTime AS FILETIME
LOCAL LastAccessTime AS FILETIME
LOCAL LastWriteTime AS FILETIME
LOCAL gfSyT AS SYSTEMTIME
LOCAL gfLT AS FILETIME
LOCAL gfCT AS FILETIME
LOCAL gfLAT AS FILETIME
LOCAL lpReOpenBuff AS OFSTRUCT
hFile = CreateFile(sFileName + CHR$(0), BYVAL %GENERIC_READ OR %GENERIC_WRITE, _
BYVAL 0, BYVAL %NULL, BYVAL %OPEN_ALWAYS, _
BYVAL %FILE_ATTRIBUTE_NORMAL, BYVAL %NULL)
IF hFile THEN
FileTimeToLocalFileTime LastWriteTime, gfLT
FileTimeToSystemTime gfLT, gfSyT
FileTimeToLocalFileTime CreationTime, gfCT
FileTimeToLocalFileTime LastAccessTime, gfLAT
gfSyT.wYear = iYear
gfSyT.wMonth = iMonth
gfSyT.wDay = iDay
gfSyT.wHour = iHour
gfSyT.wMinute = iMinute
gfSyT.wSecond = iSecond
SystemTimeToFileTime gfSyT, gfLT
LocalFileTimeToFileTime gfLT, LastWriteTime
SystemTimeToFileTime gfSyT, gfLAT
LocalFileTimeToFileTime gfLAT, LastAccessTime
SystemTimeToFileTime gfSyT, gfCT
LocalFileTimeToFileTime gfCT, CreationTime
SetFileTime BYVAL hFile, CreationTime, LastAccessTime, LastWriteTime
CloseHandle hFile
END IF
END SUB
'========================
' Main start
string gProgNam
' Set the time of a specific file to a particular date and time
gProgNam = "myfile.txt"
SetFileDate(gProgNam, 2018,04,18,18,55, 22)
print "done"