Solved

File List

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Prototype for MessageDlg in Embacadero XE 2 2 35
C++ Language error 28 186
How to convert MFC APP to Win32 APP. 19 69
Using Diagnostic tools in VS2015: Unresoved allocations 19 63
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

914 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

17 Experts available now in Live!

Get 1:1 Help Now