?
Solved

File List

Posted on 2000-02-26
5
Medium Priority
?
207 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
[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
  • 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

Independent Software Vendors: 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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

649 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