?
Solved

File List

Posted on 2000-02-26
5
Medium Priority
?
208 Views
Last Modified: 2010-05-18
How do i retrieve a list of files in a directory, without using any controls that require a user's input?
0
Comment
Question by:TheSlayer
  • 3
5 Comments
 
LVL 9

Expert Comment

by:cdesigner
ID: 2561225
use listbox and dir function
0
 
LVL 22

Expert Comment

by:nietod
ID: 2561247
Huh?  listbox?  dir function?  What are you talking about?

TheSlayer, standard C++ provides no features that support this type of thing.  It must be done using OS-specific functions and features, not standard C++ functions.  So before anyone can answer this question we would have to know what OS you are using.  
0
 

Author Comment

by:TheSlayer
ID: 2561302
Sorry folks, this is what happens when i do stuff in a hurry.
I'm using Win 98, Visual C++ 6\MFC.  I want to get a list of the files contained in a folder, then open and modify those files. I can handle the opening and modifying bits easily, but i don't know the file names, whick is why i need the list of names
0
 
LVL 22

Accepted Solution

by:
nietod earned 150 total points
ID: 2561305
For windows use the FindFirstFile() and FindNextFile() (or FindFirstFileEx() and FindNextFileEx(). functions.  I think I have an example....
0
 
LVL 22

Expert Comment

by:nietod
ID: 2561312
This is from a different question...

*******************

You can use the windows API functions FindFirstFile() and FindNextFile().

FindFirstFile() will find the first file in a directory that matches the search string (if there is one) and will fill in a WIN32_FIND_DATA structure with information about the file found.  It will also return a handle to information that windows needs to record so that it can find additional files.   You can then call FindNextFile() to find then next file that matches the search string.  You pass the handle returned from FindFirstFile() to FindNextFile() so it knows what to look for and it will fill in another  WIN32_FIND_DATA structure for the file found.  You then continue calling FindNextFile() until no more files are found.  You can then close the find handle using FindClose().

An example might be

   BOOL  Done;                     // Done searching for files?
   HANDLE  FndHnd = NULL;   // Handle to find data.
   WIN32_FIND_DATA FindDat;  // Info on file found.

   FndHnd = FindFirstFile("C:\\*.txt", &FindDat);
   Done = (FndHnd == NULL);       // Indicate we are done if nothing was found.

   while (!Done)
   {
      cout <<  FindDat.cFileName << endl; // Print name of file found.
      Done = !FindNextFile(FndHnd, &FindDat);
   }
   if (FndHnd)            // If there was anything found, then
      FindClose(FndHnd); // Close the find handle
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

830 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