Scan Folder

How can I scan a folder to get the list of all the files present in that folder?

Comments

  • : How can I scan a folder to get the list of all the files present in that folder?
    :
    In the very usefull header file 'SysUtils.hpp' use:

    [code]
    extern PACKAGE int __fastcall FindFirst(const AnsiString Path, int Attr, TSearchRec &F);
    extern PACKAGE int __fastcall FindNext(TSearchRec &F);
    extern PACKAGE void __fastcall FindClose(TSearchRec &F);
    [/code]

    Using the Help, this should be possible. If you find out how to get all files in a Folder, could you please post this? If not, could you post the failed attempt?

    See ya,


    bilderbikkel

  • : : How can I scan a folder to get the list of all the files present in that folder?
    : :
    : In the very usefull header file 'SysUtils.hpp' use:
    :
    : [code]
    : extern PACKAGE int __fastcall FindFirst(const AnsiString Path, int Attr, TSearchRec &F);
    : extern PACKAGE int __fastcall FindNext(TSearchRec &F);
    : extern PACKAGE void __fastcall FindClose(TSearchRec &F);
    : [/code]
    :
    : Using the Help, this should be possible. If you find out how to get all files in a Folder, could you please post this? If not, could you post the failed attempt?
    :
    : See ya,
    :
    :
    : bilderbikkel
    :

    Hi!! Thanks for the tip.
    I used the help and used the codes provided:

    void __fastcall TForm1::ButtonClick(TObject *Sender)
    {
    TSearchRec sr;
    int iAttributes = 0;
    if (FindFirst("C:\r", faAnyFile, sr) == 0)
    {
    do
    {
    Memo1->Text = sr.Name;
    Edit1->Text= sr.Name;

    } while (FindNext(sr) == 0);
    FindClose(sr);
    }
    }
    But in the Memo, it only displays r (that is the name of the folder)!!!

  • First some comment on your code:

    [code]
    : void __fastcall TForm1::ButtonClick(TObject *Sender)
    : {
    : TSearchRec sr;
    : int iAttributes = 0; [red]This value is never used![/red]
    : if (FindFirst("C:\r", faAnyFile, sr) == 0) [red]No wildcard[/red]
    : {
    : do
    : {
    : Memo1->Text = sr.Name;
    : Edit1->Text= sr.Name;
    :
    : } while (FindNext(sr) == 0);
    : FindClose(sr); [red]This command needs to be put after the following accolade[/red]
    : }
    : }
    [/code]

    Then the answer, you forgot the wildcard [b]*.*[/b]

    [code]
    TSearchRec sr;
    if (FindFirst("C:\*.*", faAnyFile, sr) == 0)
    {
    do
    {
    RichEdit1->Lines->Add(sr.Name);
    }
    while (FindNext(sr) == 0);
    }
    FindClose(sr);
    [/code]
    bilderbikkel

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories