1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
static void DisplayFile(string PathLetter) {
HANDLE hFile;
DWORD dwBytes2Read;
DWORD dwFilePointer;
BYTE byteFileBuff[512];
FILETIME ftCreation,
ftLastaccess,
ftLastwrite;
SYSTEMTIME stCreation,
stLastaccess,
stLastwrite;
memset(&byteFileBuff, 0, 512);
wcout<< "Please enter a file with an extension: ";
string Path = PathLetter + std::string(":\\\\");
wstring temp;
temp.assign(Path.begin(),Path.end());
wstring Filename;
wcin>> Filename;
Filename = std::wstring(temp) + Filename;
hFile = CreateFile(Filename.c_str(), GENERIC_READ,
FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, 0);
if (hFile==INVALID_HANDLE_VALUE)
{
wcout << L"CreateFile failed for " << Filename.c_str() << endl;
wcout << "with error code " << GetLastError() << endl;
return;
}
if (GetFileTime(hFile, &ftCreation, &ftLastaccess, &ftLastwrite))
{
FileTimeToSystemTime(&ftCreation, &stCreation);
FileTimeToSystemTime(&ftLastaccess, &stLastaccess);
FileTimeToSystemTime(&ftLastwrite, &stLastwrite);
wcout << "\nFile Information for: "<< Filename.c_str() << endl;
WIN32_FIND_DATA FindFileData;
cout << "Accessed: " << stLastaccess.wYear << "/" << stLastaccess.wMonth<< "/" << stLastaccess.wDay << endl;
cout << "Size: "<<GetFileSize(hFile, NULL)<<"bytes"<<endl;
dwFilePointer = SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
if (dwFilePointer != INVALID_SET_FILE_POINTER)
{
if (!ReadFile(hFile, byteFileBuff, 512, &dwBytes2Read, NULL))
{
printf("Error in Reading Root Entry.\n");
}
else
{
BYTE *pRoot = byteFileBuff;
tdFILE *pFileRecord = (tdFILE *)pRoot;
}
}
} else
cout << "Error code: " << GetLastError() << endl;
CloseHandle(hFile);
}
|