给出一个我以前写的例子,做个善事,哈哈。自己领悟一下。
关键是得到这个东西:fdData.cFileName (文件名),
和这个:隐藏属性
if(fdData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
strcat(tcAttrib , "隐藏 ");
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
WIN32_FIND_DATA fdData ={0};
bool bFind ;
HANDLE hFind = FindFirstFile("C:\\*.txt", &fdData );
if(hFind == INVALID_HANDLE_VALUE)
return -1 ;
SYSTEMTIME sysTime ;
char tcBuffer[256] = {0} , tcAttrib[256] = {0};
printf("%-20s%-20s%-20s%-20s\n" , "文件名" , "创建时间" ,"文件大小(byte)" , "文件属性");
do{
memset(tcBuffer , 0 , 256);
memset(tcAttrib , 0 , 256);
if(fdData.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE)
strcat(tcAttrib , "存档 ");
if(fdData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
strcat(tcAttrib , "隐藏 ");
if(fdData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
strcat(tcAttrib , "只读 ");
if(fdData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)
strcat(tcAttrib , "系统 " );
//把文件时间转换为系统时间
FileTimeToSystemTime(&fdData.ftCreationTime , &sysTime) ;
wsprintf(tcBuffer , "%2d/%2d/%2d %2d:%2d:%2d",sysTime.wYear , sysTime.wMonth ,
sysTime.wDay , sysTime.wHour , sysTime.wMinute , sysTime.wSecond);
printf("%-20s%-20s%-20d%-20s\n" , fdData.cFileName, tcBuffer , fdData.nFileSizeLow , tcAttrib);
bFind = FindNextFile(hFind , &fdData)
;
}while(bFind);
FindClose(hFind) ;
return 0;
}
[
本帖最后由 toofunny 于 2013-10-20 01:04 编辑 ]