Thread: recursive search

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    18

    Question recursive search

    I am doing a recursive searching the "C:\" drive on a Windows PC with FindFirstFile and FindNextFile. I am not the administrator and the program stops when I hit a directory that when I do a ls -l from the command prompt shows the directory as "Permission denied". How can the program determine if it doesn't have permission to access a directory? Thanks

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Can you post the code you're using?

    EDIT: Maybe GetFileAttributes() would work, but I'm not really sure.
    Last edited by bennyandthejets; 09-28-2003 at 06:16 PM.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463

    Re: recursive search

    Originally posted by bhorrobi
    How can the program determine if it doesn't have permission to access a directory? Thanks
    The FindFirstFile / FindNextFile APIs fill a WIN32_FIND_DATA structure pointed by lpFindFileData ). The dwFileAttributes data member of this struct contains the attributes needed by you:

    Code:
    typedef struct _WIN32_FIND_DATA {
      DWORD    dwFileAttributes; 
      FILETIME ftCreationTime; 
      FILETIME ftLastAccessTime; 
      FILETIME ftLastWriteTime; 
      DWORD    nFileSizeHigh; 
      DWORD    nFileSizeLow; 
      DWORD    dwReserved0; 
      DWORD    dwReserved1; 
      TCHAR    cFileName[ MAX_PATH ]; 
      TCHAR    cAlternateFileName[ 14 ]; 
    } WIN32_FIND_DATA, *PWIN32_FIND_DATA;
    On the other hand, you should check the return values of FindFirstFile / FindNextFile, in case of failure evaluate the error given by GetLastError().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  2. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Linear Search: the recursive way.
    By Nutshell in forum C Programming
    Replies: 7
    Last Post: 01-15-2002, 03:15 AM