Get file property creation time, access time, and modification time//The CreateFile here only causes the file to be read-only and cannot have other permissions, preferably with FindFile to get created, modified, and access time void Get_file_create_modify_ Access_time () {std_string str_create_time, str_access_time, Str_modify_time; FILETIME ftcreate, Ftaccess, ftmodify;std::string strfilepath;strfilepath.assign ("C://1.txt"); HANDLE hfile = Createfilea (Strfilepath.c_str (), Generic_read, File_share_read, null,open_existing, FILE_FLAG_BACKUP_ Semantics, NULL); if (Getfiletime (hfile, &ftcreate, &ftaccess, &ftmodify)) {SYSTEMTIME stlocal; ZeroMemory (&stlocal, sizeof (SYSTEMTIME)); FileTimeToSystemTime (&ftcreate, &stlocal);//Note: FileTimeToSystemTime Get the system time hours is smaller than the actual 8 hours, so add can Str_create_ Time. AppendFormat ("%04d-%02d-%02d%02d:%02d:%02d", Stlocal.wyear, Stlocal.wmonth, Stlocal.wday, StLocal.wHour + 8, Stlocal.wminute, Stlocal.wsecond); File creation time ZeroMemory (&stlocal, sizeof (SYSTEMTIME)); FileTimeToSystemTime (&ftmodify, &stlocal); Str_modify_time. AppendFormat ("%04d-%02d-%02d%02d:%02d:%02d", Stlocal.wyear, stlocal.Wmonth, Stlocal.wday, Stlocal.whour + 8, Stlocal.wminute, Stlocal.wsecond); File modification Time ZeroMemory (&stlocal, sizeof (SYSTEMTIME)); FileTimeToSystemTime (&ftaccess, &stlocal); Str_access_time. AppendFormat ("%04d-%02d-%02d%02d:%02d:%02d", Stlocal.wyear, Stlocal.wmonth, Stlocal.wday, StLocal.wHour + 8, Stlocal.wminute, Stlocal.wsecond); File access time return;}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Get file creation time, last modified time, access time