Solved

CFileFind doesn't find System Directory !!!

Posted on 1999-01-05
3
415 Views
Last Modified: 2013-11-20
This quite short code returns false with GetlastErorr = 18 (no more file). I don't understand what I'm doing wrong.

CFileFind            theFileFinder;
BOOL            result1, result2;

result1 = theFileFinder.FindFile("C:\\WINNT\\system32");
if (result1)
   result2 = theFileFinder.FindNextFile();

>>> My goal is to call GetCreationTime after this to get the system directory creation date (of course I won't use the constant string but I'll use "GetSystemDirectory").

Thanks for any hint.
0
Comment
Question by:SergeDePauw
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
nil_dib earned 100 total points
ID: 1327219
You did nothing wrong!
FindNextFile finds the next file from A PREVIOUS call to
FindFile. You have only ONE directory which is called "C:\\WINNT\\system32",
so FindNextFile must return false because no more directorys with this name exist!
If you write FindFile("*.*") then FindNextFile will return true because there are more files than match "*.*".
0
 

Author Comment

by:SergeDePauw
ID: 1327220
That's maybe correct but a call to GetCreationTime fails if I don't call FindNextFile (as stated in the doc.).

Does that mean it is not possible to access a file directly but that I need to find the "previous" file first and then use "FindNextFile" to get the one I need. That's quite ridiculous to me.

So I found another way. I use the Win32 function "FindFIrstFile" and it works much better than the MFC object.

Thank you for your time.
0
 
LVL 4

Expert Comment

by:nil_dib
ID: 1327221
Ok,
I see thats really confusing ...
Another way is to use GetFileAttributesEx:
WIN32_FILE_ATTRIBUTE_DATA g;
GET_FILEEX_INFO_LEVELS h;
GetFileAttributesEx("C:\\winnt\\system32", h, (void*)&g);

or GetFileInformationByHandle:
BY_HANDLE_FILE_INFORMATION info;
HANDLE hFile = CreateFile ( ("C:\\winnt\\system32",
            GENERIC_READ,
            0,
            NULL,
            OPEN_EXISTING,
            FILE_ATTRIBUTE_SYSTEM,
            NULL );
GetFileInformationByHandle( hFile, &info );

regards nil_dib
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl Awk Need Help 3 109
zeroFront challenge 7 79
Fibonacci challenge 11 108
wordcount challenge 11 101
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now