Get file creation time, last modified time, access time

Source: Internet
Author: User

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

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.