Search problem

Suppose i have a simple form
1- edit box
2- command button
3- rich text editor OR Memo

how to make a fn that searches a specified path (Edit Box) and subfolders for certain files
i.e.
*.jpg; image.*; *.*; image.jpg
and show their pathes in (Rich text editor) one line each.

i posted message like this in C/C++ board but here i need it GUI not in CLI, so don't mentin that i posted it towice.
thanx,
Nasim.

Comments

  • Search 'SysUtils.hpp'. In it (at the bottom) you will also find the functions FindFirstFile() and FindNextFile() as well as many other usefull functions for you. Good luck,
    bilderbikkel

  • : Search 'SysUtils.hpp'. In it (at the bottom) you will also find the functions FindFirstFile() and FindNextFile() as well as many other usefull functions for you. Good luck,
    : bilderbikkel
    :
    :
    well, but i still can't search subfolders even when using wildcards
    "c:\images\*\*.jpg" the first star result in "no thing happen"

    help me please how to search subfolders

    thanx in advance
    Nasim

  • [b][red]This message was edited by luckyboy at 2006-7-25 11:39:34[/red][/b][hr]
    Well, FindFirst and FinNext can't support subfolders in this wildcard form, it just uses this form to specify the type of files and/or their names.
    To search into subfolders as well, we will use two loops, one for searching files into current folder and another to search for subfolders into the current one, then we may pass this new path to search for files into.

    [code]
    long get_files(AnsiString PATH, AnsiString TYPE)
    {
    TSearchRec FilesSearchRec;
    long jpgCounter = 0;

    if(!FindFirst(PATH+"\*."+TYPE, faAnyFile, FilesSearchRec))
    {
    do
    {
    ++jpgCounter;
    }
    while(!FindNext(FilesSearchRec));
    }

    return jpgCounter;
    }
    //----------------------------------------
    void get_subfl(AnsiString PATH, AnsiString TYPE)
    {
    TSearchRec SubflSearchRec;
    long subflCounter = 0;
    long numberOfJpgs = 0;

    if(!FindFirst(PATH+"\*.*", faAnyFile, SubflSearchRec))
    {
    do
    {
    if(SubflSearchRec.Name != ".." && SubflSearchRec.Name != "." && (SubflSearchRec.Attr & faDirectory))
    {
    ++subflCounter;
    numberOfJpgs = get_files(PATH+"\"+SubflSearchRec.Name, TYPE);
    frmMain->rchInformation->Lines->Add(SubflSearchRec.Name+" has "+numberOfJpgs+" "+TYPE+" file(s).");
    }
    }
    while(!FindNext(SubflSearchRec));
    }
    frmMain->StatusBar1->SimpleText = IntToStr(subflCounter) + " folder(s)";
    }
    [/code]

    this code just go one level in depth. i.e. if you have folder contain subfolders like my problem it will be great, but if your subfolders contain sub-subfolders you may think about Recursion or any condition to break the loop.

    Mohammad Nasim


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