我需要帮助打印属于WIN32_FIND_DATA结构的属性

时间:2012-04-01 10:27:18

标签: c winapi

我试图打印WIN32_FIND_DATA属性结构ftCreationTime,所以我把%d打印出来但是它给了我负数,我试过%f然后它给了我零,我需要帮助请?

#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;
}

1 个答案:

答案 0 :(得分:1)

WIN32_FIND_DATA::ftCreationTime的类型为FILETIME。您需要使用FileTimeToSystemTime()将其转换为系统时间,然后将其打印出来。

要打印SYSTEMTIME,您只需要打印结构的字段,就像打印WIN32_FIND_DATA结构一样。

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);