Sometimes, for some synchronization or other messy reasons, we need to modify the file creation date and other content. I found an algorithm on the Internet and wrote it down for future use.
Void cmodifybindlg: onbutton1 ()
{
// Todo: add your control notification handler code here
// Define a structure compatible with the file information to save the obtained information
Typedef struct _ file_info {
Tchar szfiletitle [128]; // file title name
DWORD dwfileattributes; // file attributes
Filetime ftcreationtime; // File Creation Time
Filetime ftlastaccesstime; // last Object Access time
Filetime ftlastwritetime; // The last modification time of the object
DWORD nfilesizehigh; // high dual-character file size
DWORD nfilesizelow; // low dual-Text of the file size
DWORD dwreserved0; // reserved, 0
DWORD dwreserved1; // reserved, 0
} File_info, * pfile_info;
// Obtain the object information
Win32_find_data FFD;
Handle hfind = findfirstfile (m_filename, & FfD );
Findclose (hfind );
// Save the file information
File_info fileinfo;
Memset (& fileinfo, 0, sizeof (file_info ));
// Save the file property information to fileinfo for backup
Strcpy (fileinfo. szfiletitle, FFD. cfilename );
Fileinfo. dwfileattributes = FfD. dwfileattributes;
Fileinfo. ftcreationtime = FfD. ftcreationtime;
Fileinfo. ftlastaccesstime = FfD. ftlastaccesstime;
Fileinfo. ftlastwritetime = FfD. ftlastwritetime;
Fileinfo. nfilesizehigh = FfD. nfilesizehigh;
Fileinfo. nfilesizelow = FfD. nfilesizelow;
// Modify the file generation date
Systemtime time;
Filetime t_ft;
Filetimetosystemtime (& (FfD. ftcreationtime), & time );
Time. wyear = 2000;
Time. wmonth = 1;
Time. wday = 1;
Time. wdayofweek = 6;
Systemtimetofiletime (& time, & t_ft );
// Write the modified date back to the file
Fileinfo. ftcreationtime = t_ft;
Bool bresult;
Cfile file (m_filename, cfile: modewrite | cfile: typebinary); // open the file
Bresult = setfiletime (handle) file. m_hfile, // file handle to be written
& Fileinfo. ftcreationtime, // File Creation Time
& Fileinfo. ftlastaccesstime, // last file access time
& Fileinfo. ftlastwritetime); // last file modification time
If (! Bresult)
{
DWORD dwerr = getlasterror ();
}
// Setfileattributes ();
File. Close (); // close the file
}