Grabbing file list from a directory - Help needed - Programmer

This is a discussion on Grabbing file list from a directory - Help needed - Programmer ; Hi All, I trying to get the *.txt files from a directory and to process it. But I am facing difficulties in grabing the list of *.txt files. For eg : If Folder name : {Sample} Files under it : ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Grabbing file list from a directory - Help needed

  1. Grabbing file list from a directory - Help needed

    Hi All,

    I trying to get the *.txt files from a directory and to process it. But
    I am facing difficulties in grabing the list of *.txt files.

    For eg :
    If
    Folder name : {Sample}
    Files under it : {a.txt, b.bat,c.txt,d.dll,e.txt}
    then have to place {a.txt,c.txt,e.txt} into a vector.
    Please help. Thanks in advance.


  2. Re: Grabbing file list from a directory - Help needed

    I am not really sure where you are running into trouble. You need to be more
    specific.

    But here is a very general solution in MFC

    If you don't want to check subdirectories:


    typedef CList StringList;

    void PutFilesInList(CString Directory,StringList &List)
    {
    CFileFind Finder;
    BOOL Working = Finder.FindFile(Directory+\\*.txt);
    while (Working)
    {
    Working = Finder.FindNextFile();
    if (!Finder.IsDirectory())
    {
    List.AddHead(Finder.GetFilePath());
    }
    }
    }

    if you want to check sub directories too:

    typedef CList StringList;


    void PutFilesInList(CString Directory,StringList &List)
    {
    CFileFind Finder;
    BOOL Working = Finder.FindFile(Directory+"\\*.*");
    while (Working)
    {
    Working = Finder.FindNextFile();
    if (!Finder.IsDots())
    {
    if (!Finder.IsDirectory())
    {
    char Filename[MAX_PATH];
    char Filename[MAX_PATH];
    _splitpath(Finder.GetFilePath(),NULL,NULL,Filename ,Ext);
    if (stricmp(Ext,".txt") == 0)
    {
    List.AddHead(Finder.GetFilePath());
    }
    }
    else
    {
    PutFilesInList(Finder.GetFilePath(),List);
    }
    }
    }
    }

    AliR.

    "Baskar" wrote in message
    news:1107354092.501736.26540@l41g2000cwc.googlegro ups.com...
    > Hi All,
    >
    > I trying to get the *.txt files from a directory and to process it. But
    > I am facing difficulties in grabing the list of *.txt files.
    >
    > For eg :
    > If
    > Folder name : {Sample}
    > Files under it : {a.txt, b.bat,c.txt,d.dll,e.txt}
    > then have to place {a.txt,c.txt,e.txt} into a vector.
    > Please help. Thanks in advance.
    >




  3. Re: Grabbing file list from a directory - Help needed

    Thanks a lot Gentleman. It really helped.


+ Reply to Thread