So far I have come up with three ways to do the EXACT SAME THING. Namely, get the creation date of an arbitrary file, is there something that I am missing? Is there a difference between these three methods or do they just exist for the sake of redundancy? Is there an advantage to using a particular method?
METHOD: THE FIRST
METHOD: THE SECONDCode:string GetFileCreationDate(char* pFileName) { stringstream ss; WIN32_FILE_ATTRIBUTE_DATA wfad; SYSTEMTIME st; GetFileAttributesEx(pFileName, GetFileExInfoStandard, &wfad); FileTimeToSystemTime(&wfad.ftCreationTime, &st); ss << st.wMonth << '/' << st.wDay << '/' << st.wYear; return ss.str(); }
METHOD: THE THIRDCode:string GetFileCreationDateEx(char* pFileName) { stringstream ss; HANDLE hFileHandle = CreateFile(pFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); FILETIME ft; SYSTEMTIME st; GetFileTime(hFileHandle, &ft, NULL, NULL); FileTimeToSystemTime(&ft, &st); ss << st.wMonth << '/' << st.wDay << '/' << st.wYear; CloseHandle(hFileHandle); return ss.str(); }
Code:string GetFileCreationDateExEx(char* pFileName) { stringstream ss; HANDLE hFileHandle = CreateFile(pFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); BY_HANDLE_FILE_INFORMATION bhfi; SYSTEMTIME st; GetFileInformationByHandle(hFileHandle, &bhfi); FileTimeToSystemTime(&bhfi.ftCreationTime, &st); ss << st.wMonth << '/' << st.wDay << '/' << st.wYear; CloseHandle(hFileHandle); return ss.str(); }



LinkBack URL
About LinkBacks


