Getting wrong file creation date

Hi everybody,
I'm trying to make a program to get the file creation or access or modification date, but the program always is returning me this date "Thu Jan 1 01:00:00 1970". I tried lots of codes and heelps from the forum, of posts from other users, but the result is always the same, and I complied the code and run in many machines XP and Win7.

Here you are the code:

bool ListDirectoryContents(const char *sDir) {
WIN32_FIND_DATA fdFile = {0};
HANDLE hFind = NULL;
ULONGLONG fileSize;
time_t rawtime;
struct tm * timeinfo2;


long bsize;
float kbsize;

char sPath[2048];

sprintf(sPath, "%s\\*.*", sDir);

if ((hFind = FindFirstFile(sPath, &fdFile)) == INVALID_HANDLE_VALUE) {
printf("Path not found: [%s]\n", sDir);
return false;
}

do {
if (strcmp(fdFile.cFileName, ".") != 0 && strcmp(fdFile.cFileName, "..") != 0) {
sprintf(sPath, "%s\\%s", sDir, fdFile.cFileName);

if (fdFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
ListDirectoryContents(sPath);
} else {
cout << "# FILE NAME: ######################################################" << endl;
cout << "File: " << sPath << endl;
cout << "# FILE SIZE INFO: #################################################" << endl;
bsize = fdFile.nFileSizeLow;
kbsize = (float) bsize / 1024;
cout << "SIZE: " << fdFile.cFileName << " " << bsize << " bytes " << kbsize << " kb" << endl;
cout << "size HIGH: " << (fdFile.nFileSizeHigh * (MAXDWORD + 1)) + fdFile.nFileSizeLow << endl;
fileSize = fdFile.nFileSizeHigh;
fileSize <<= sizeof ( fdFile.nFileSizeHigh) * 8;
fileSize |= fdFile.nFileSizeLow;
cout << "fileSize: " << (DWORD) fileSize << endl;
cout << "# FILE ACCESS INFO: ################################################" << endl;
time((time_t*) & fdFile.ftLastAccessTime);
cout << " --> last open: " << ctime((const time_t*) &fdFile.ftLastAccessTime) << endl;
}
}
} while (FindNextFile(hFind, &fdFile));
FindClose(hFind);
return true;
}

int main() {
ListDirectoryContents("C:\\Repository_Files\\");
return 0;
}
Please read this carefully:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724284(v=vs.85).aspx


This is an example from Microsoft, uses GetFileTime(), but is similar in concept:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724926(v=vs.85).aspx
Last edited on
Topic archived. No new replies allowed.