how would i get a list of files in directorys in any given directory?
use the findfirstfile and then findnextfile commands with a *.* paramater as the filename? or maybe the ex ones?
This is a discussion on getting a list of files and dirs within the Windows Programming forums, part of the Platform Specific Boards category; how would i get a list of files in directorys in any given directory? use the findfirstfile and then findnextfile ...
how would i get a list of files in directorys in any given directory?
use the findfirstfile and then findnextfile commands with a *.* paramater as the filename? or maybe the ex ones?
let us eat and drink
You can use the FindFirstFile & FindNextFile Apis....Originally posted by Andrewthegreen
how would i get a list of files in directorys in any given directory?
use the findfirstfile and then findnextfile commands with a *.* paramater as the filename? or maybe the ex ones?
Code:#include <windows.h>//For FindFirstFile etc #include <iostream>//For cout etc #include <string>//For...well...ugh...string! using std::string; using std::cout; using std::cin; using std::endl; int main(int argc,char** argv){ WIN32_FIND_DATA wfd;//This holds the data on a found file string str;//To hold directory path cout << "Enter Directory to list files for" << endl; cin >> str;//Get path str += "\\*.*";//Add this to indicate we want all files HANDLE hFile = FindFirstFile(str.c_str(),&wfd);//Find first if(hFile ==INVALID_HANDLE_VALUE){//If error..abort cout << "Error!! Aborting" << endl; return 1; } do{ cout << wfd.cFileName << endl; }while(FindNextFile(hFile,&wfd));//Get the rest of the files FindClose(hFile);//Clean up! return 0; }
and if you only wanted the files, then just AND the attributes parameter with the FILE_ATTRIBUTE_DIRECTORY, and NOT the whole thing.
Here's what I mean: (following from Fordy's code)
Code:do{ if( !(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) cout << wfd.cFileName << endl; }while(FindNextFile(hFile,&wfd));//Get the rest of the files
gosh, thanks! its not really for me, so ill put your names on it
let us eat and drink