Solved

File List

Posted on 2000-02-26
5
185 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 50 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

760 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