Reputation: 43
I'm trying to print the WIN32_FIND_DATA Attribute struct ftCreationTime, so I put %d to print it but it's giving me negative number, I tried %f and then it gave me zero, I need help please?
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
int _tmain(int argc, _TCHAR* argv[])
{
FILETIME a ;
WIN32_FIND_DATA x;
HANDLE s=FindFirstFile(L"d:\\uni\\*.*",&x);
if(s==INVALID_HANDLE_VALUE)
{
printf("Search failed!\n");
return 0;
}
if((x.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ==0)
_tprintf(L"The first file name is: %s\n",x.cFileName);
else
_tprintf(L"The first directory name is: %s\n",x.cFileName);
while(FindNextFile(s,&x))
{
if((x.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ==0)
_tprintf(L"The file name is: %s and the size is %d %d\n",x.cFileName,x.nFileSizeLow , x.ftCreationTime);
else
_tprintf(L"The directory name is: %s\n",x.cFileName );
}
FindClose(s);
return 0;
}
Upvotes: 0
Views: 1160
Reputation: 1529
WIN32_FIND_DATA::ftCreationTime
is of type FILETIME
. You need to use FileTimeToSystemTime()
to convert it to system time, then print it.
To print SYSTEMTIME
, you just need to print the fields of the structure like how you print the WIN32_FIND_DATA struct.
SYSTEMTIME systemTime;
FileTimeToSystemTime(&x.ftCreationTime, &systemTime);
_tprintf(_T("The creation time is %02d-%02d-%d %02d:%02d:%02d\n"),
systemTime.wMonth, systemTime.wDay, systemTime.wYear,
systemTime.wHour, systemTime.wMinute, systemTime.wSecond);
Upvotes: 1