Click to See Complete Forum and Search --> : c++/linux question: files & directories


dunno
02-18-2001, 09:41 PM
I want my function to be able to look in a directory and fill an array/vector with the filenames of all the files in that directory so that I can open them and read them into my program. Is there some way I can do this?

Strike
02-18-2001, 10:10 PM
There are functions like readdir and others that will do this. Poke around the section 3 man pages, looking for directory stuff and see if you can find more.

pinoy
02-21-2001, 12:53 AM
Look at opendir, and readdir

Here's a simple untested code, at best this is only pseudo code


struct DIR* dp;
struct dirent* dir;

dp = opendir( "/usr/bin" );
assert( dp );
while ( !(dir = readdir( dp )) ) {
printf( "inode: %d, name: %s\n", dir->d_ino, dir->d_name );
}