0

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

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Ancient Dragon
0

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

Edited by Ancient Dragon: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.