can someone tell me how can i list all the .txt files of a directory or folder by a c++ program.
please tell .

i have tried

void f_ListFile()
{
    system("cls");

    system("DIR /b D:\\*.txt");
     getch();
}

it is working for this but when it is something like this below

void f_ListFile()
{
    system("cls");
    //system("DIR D:\\ /P /A:-D-H /O:N -E*.txt");
    system("DIR /b C:\Documents and Settings\malaya\My Documents\Visual Studio 2008\\*.txt");
     getch();
}

then this fails ...

i know the reason that when in command it is given DIR then it wont go inside the folders ... and thats all the problem that i have to go into a folder..
so please help me

what compiler are you using? If you are using a 32-bit compiler then you can use win32 api functions FindFirstFile() and FindNextFile(). google for those functions and you will find example programs how to use them. But if you are using something like Turbo C then there may be no solution for you because that compiler can not use paths and file names that have spaces or are longer than 8.3