searching for hidden files using winapi
HI i want to search for a hidden files and directories in a specefic given path but I don't know how to do it for hidden files i do know how to search for normal files and dir i did this code but im stuck can't make it search for only hidden files
#include "stdafx.h"
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR *fn;
fn=L"d:\\*";
HANDLE f;
WIN32_FIND_DATA data;
{
FILE_ATTRIBUTE_HIDDEN;
}
f=FindFirstFile(fn,&data);
if(f==INVALID_HANDLE_VALUE){
printf("not found\n");
return 0;
}
else{
_tprintf(L"found this file: %s\n",data.cFileName);
开发者_如何学编程 while(FindNextFile(f,&data)){
_tprintf(L"found this file: %s\n",data.cFileName);
}
}
FindClose(f);
return 0;
}
The WIN32_FIND_DATA structure isn't telling FindFirstFile/FindNextFile what to search for; it's returning the results of the search. You need to do a bit mask on the dwFileAttributes member to determine if the file is hidden or not.
if ((data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0)
WIN32_FIND_DATA holds files attributes member
http://msdn.microsoft.com/en-us/library/aa365740(VS.85).aspx
dwFileAttributes
verify it againts FILE_ATTRIBUTE_HIDDEN (avoid FILE_ATTRIBUTE_DIRECTORY items)
精彩评论