Solved

File List

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

707 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