tags:

views:

36

answers:

2

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;
}
A: 

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)

Bartosz Wójcik
+2  A: 

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)
Mark Ransom