I have made a simple program that displays the directory but i just want it to display the files with the extention .txt Does anyone know how to modify this to make it so it does that instead of displaying the whole directory
Check to see if the last four characters in the filename are ".txt", and only print the name if they are.
1 2 3 4 5 6 7
string name = pdir->d_name; // the file name
name.erase( 0, name.find_last_of( '.' ) ); // the last four digits of the file name
transform( name.begin(), name.end(), name.begin(), ptr_fun <int, int> ( tolower ) ); // make it lowercase
if (name == ".txt")
{
cout << pdir->d_name << endl;
}
I tried it and when i test the function out it just says .txt as the output. It doesn't display the files with the extention .txt. I want to display whats before the .txt :P