Solved

CFileFind doesn't find System Directory !!!

Posted on 1999-01-05
3
413 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 6 48
FizzBuzz challenge 9 72
Sed question 2 45
Problem to open Excel file 15 39
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

18 Experts available now in Live!

Get 1:1 Help Now