Advertisement

Listing files

Started by August 03, 2000 05:07 PM
1 comment, last by xstreme2000 24 years, 4 months ago
I need a list of all the files in a directory using msvc++ no MFC and I just wanted to know if _findfirst()/_findnext() from io.h is the best method of doing this?
tom.oram@vodafone.net
I had to do this for a project I am working on. Here is code to read the from the Directory.

        CString Pathname("j:\\images\\"); // The PathCString FileTypes("*.jpg"); // File TypesCString CompPath(Pathname + FileTypes);	// Set Up Everything for Directorylong fh; // File Handlestruct _finddata_t findData; // Creating an Instance of finddate structfh = _findfirst(CompPath, &findData);  // Set it to the first file in direc// Set up some things to print to file withif ( fh == -1 ) // Load Failed{    cout << "Cannot Open Path\n";return;}else{    cout << "Listing Files In " << Pathname << "\n\n";cout << "FileName\t\t\tTime & Date Created\n";while ( _findnext( fh, &findData ) == 0 ) // Keep looking until it can't find one{        cout << findData.name << "\t\t" << "\t\t\t" << ctime(&(findData.time_create)); // Print To Screen what it found } }// Clear Memorycout << "\n";_findclose(fh);        


Edited by - Neo_Matrix on August 3, 2000 8:55:42 PM

Edited by - Neo_Matrix on August 3, 2000 8:57:14 PM
Neo_Matrix
Advertisement

Neo_Matrix:

Noticed that you appear to be using MFC (the CString reference is a giveaway.. ). If you are already using MFC, they have a nice little class called CFileFind that is easy to use.

HTH

This topic is closed to new replies.

Advertisement