?
Solved

CFileFind doesn't find System Directory !!!

Posted on 1999-01-05
3
Medium Priority
?
434 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
nil_dib earned 300 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 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