Solved

CFileFind doesn't find System Directory !!!

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 66
no14 challenge 14 72
mapAB Challlenge 35 158
how to use laptop or pad camera in vb.net windows application 2 86
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: 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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

828 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