Search Files in Subdirectories

Login to reply to this topic.
Mon, 2005-03-21 07:53
Joined: 2005-03-21
Forum posts: 45
Hi,

Can any one please tell me how to search for files(ex : *.mp3) in a directory and in its sub directories.

Thanks in advance.

Regards,
Prabhu.

Mon, 2005-03-21 09:09
Joined: 2004-07-28
Forum posts: 1379
Search Files in Subdirectories
TFindFile.  Have a look in the SDK for some examples.

didster

Mon, 2005-03-21 09:16
Joined: 2005-03-21
Forum posts: 45
Search Files in Subdirectories
Quote from: didster
TFindFile.  Have a look in the SDK for some examples.

Hi,

But the TFindFile helps us to search only files in a particular directory and not in the sub directories.
Mon, 2005-03-21 09:49
Joined: 2004-07-28
Forum posts: 1379
Search Files in Subdirectories
So?  Just call it once for each dir rescursivly:

Code:
void ScanStartL(RFs aFs, const TDesC& aPath, const TDesC& aWild, CDesCArray* aArray)
{
CDirScan* scan = CDirScan::NewLC(aFs);
scan->SetScanDataL(aPath, KEntryAttDir|KEntryAttMatchExclusive, ESortNone, CDirScan::EScanDownTree);

FOREVER
{
CDir* dir = NULL;
TRAPD(error, scan->NextL(dir));
if (error || !dir)
break;

delete dir;

ScanDirL(aFs, scan->FullPath(), aWild, aArray);
};
CleanupStack::PopAndDestroy(scan);
}


void ScanDirL(RFs& aFs, const TDesC& aDir, const TDesC& aWild, CDesCArray* aArray)
{
TParse parse;
parse.Set(aWild, &aDir, NULL);
TPtrC spec(parse.FullName());

TFindFile find(aFs);
CDir* dir;

if (!find.FindWildByPath(parse.FullName(), NULL, dir))
{
CleanupStack::PushL(dir);

for(int i = 0; i < dir->Count(); i++)
{
parse.Set((*dir)[i].iName, &spec, NULL);
aArray->AppendL(parse.FullName());
}

CleanupStack::PopAndDestroy(dir);
}
}

Then, to say find all the mp3s in "C:\T" its sub dirs, do this:

Code:

RFs aFs;
aFs.Connect();
CleanupClosePushL(aFs);
CDesCArrayFlat* aFiles = new (ELeave) CDesCArrayFlat(4);
CleanupStack::PushL(aFiles)

ScanStartL(aFs, _L("C:\\T\\"), _L("*.mp3"), aFiles);

//
// files are now in "aFiles"

CleanupStack::PopAndDestory(aFiles);
CleanupStack::PopAndDestory(&aFs);


In that code, aFiles will have "C:\\T\\a.mp3", ":C:\\T\\B\\b.mp3" or what ever in.

didster

Mon, 2005-03-21 10:27
Joined: 2005-03-21
Forum posts: 45
Search Files in Subdirectories
Hi,

Thanks a lot  Cheezy

Regards,
Prabhu.
Mon, 2005-06-20 23:37
Joined: 2003-09-20
Forum posts: 3
Re: Search Files in Subdirectories
Hi,

I think that you could check RApaLsSession for getting installed applications.
There is a similiar thread on the Board

Best regards
SW Team

Best regards
SymbWorks

Tue, 2006-02-21 16:43
Joined: 2003-10-20
Forum posts: 35
Re: Search Files in Subdirectories
Hi didster,

did you notice that if you use FindWildbyPath to scan "c:\" and a file is found in dir c:\, for istance c:\hello.mp3, that file is found in each directory scanned?  Huh

I tested this behaviour both on emulator and on device (N6630, N6600).

Everythings ok (file found exactly ONE time) if the file is in the root of MMC (for example: e:\hello.mp3).

Fabriz


I often regret my speech, I never regret my silence

Wed, 2006-02-22 10:47
Joined: 2003-10-20
Forum posts: 35
Re: Search Files in Subdirectories
I've completed your Display() method....hope this helps.
The dialog listbox is not the same but I don't think it's a big issue modify it.

void CMyAppUi::display()
{

RFs aFs;
aFs.Connect();
CleanupClosePushL(aFs);
CDesCArrayFlat* aFiles = new (ELeave) CDesCArrayFlat(4);
CleanupStack::PushL(aFiles);

ScanStartL(aFs, _L("c:\\clips\\"), _L("*.mp3"), aFiles);



TInt index;
   // CAknSelectionListDialog* dialog = CAknSelectionListDialog::NewL(index, aFiles, 0);
    CAknListQueryDialog* dlg = new( ELeave ) CAknListQueryDialog( &index );
               dlg->PrepareLC(R_LIST_DIALOG);
               CDesCArray *itemTextArray = new (ELeave) CDesCArrayFlat(1);
               dlg->SetItemTextArray(itemTextArray);

               for( TInt i = 0; i < aFiles->Count(); i++ )
               {
                  TBuf<256> item;
                  item.Format(_L("%S"), &(aFiles->At(i)) );
                  itemTextArray->AppendL(item);             

               }

               dlg->RunLD()
               
        // Load cba, menu, etc as necessary
       iAppView->SetCommandSetL(R_SOFTKEYS);
        //iEikonEnv->AppUiFactory()->MenuBar()->SetMenuTitleResourceId(R_MENUBAR);
    }
//
// files are now in "aFiles"

CleanupStack::PopAndDestroy(aFiles);
CleanupStack::PopAndDestroy(&aFs);

}


I often regret my speech, I never regret my silence

Wed, 2006-02-22 13:10
Joined: 2003-10-20
Forum posts: 35
Re: Search Files in Subdirectories
Use

  item.Format(_L("%S"), &( (*aFiles)[i] ) );

instead of

  item.Format(_L("%S"), &(aFiles->At(i)) );

I often regret my speech, I never regret my silence

Thu, 2006-02-23 10:04
Joined: 2003-10-20
Forum posts: 35
Re: Search Files in Subdirectories
Hi,

I use this code snippet without any problem...probably your resource in rss does not fit with CAknListQueryDialog.
For this reason I attach the resource I use:

RESOURCE DIALOG r_list_query
{
flags = EGeneralQueryFlags;
buttons = R_AVKON_SOFTKEYS_OK_CANCEL;
items =
{
DLG_LINE
{
type = EAknCtListQueryControl;
id = EListQueryControl;
control = AVKON_LIST_QUERY_CONTROL
{
listtype = EAknCtSinglePopupMenuListBox;
listbox = LISTBOX
{
flags = EAknListBoxMenuList;
height = 3;
width = 10;
array_id = r_demo_list_query_item;
};
heading = qtn_akntanote_select_playlist;
};
}
};
}


RESOURCE ARRAY r_demo_list_query_item
{
items =
{
LBUF {txt = "First item"; },
LBUF {txt = "Second item"; },
LBUF {txt = "Third item"; }
};
}

I hope this is the right suggestion

Fabriz

I often regret my speech, I never regret my silence

Thu, 2006-02-23 11:13
Joined: 2003-10-20
Forum posts: 35
Re: Search Files in Subdirectories
Look at SDK doc for TParse / TParsePtr class

I often regret my speech, I never regret my silence

Thu, 2006-02-23 11:50
Joined: 2005-10-06
Forum posts: 13
Re: Search Files in Subdirectories
Thanks For ur suggestion.
If u have any sample program for this ,Can u please forward to me

Regards,
Meghana
Fri, 2006-02-24 07:16
Joined: 2005-10-06
Forum posts: 13
Re: Search Files in Subdirectories
Hi,

I got it.how to show only manes & not the full path.
Just a small change
Instead  of
aArray->AppendL(parse.FullName());
Use
aArray->AppendL(parse.Name());

Thanks a lot for ur help.

Regards,
Meghana
Tue, 2006-02-28 06:37
Joined: 2005-10-06
Forum posts: 13
Re: Search Files in Subdirectories
Hi,
  After displaying the list. i want to select the file ..using enter key ok..but i am not getting the handellistbox event or key response so that can use the selected file for further processing.
one function currentfilename() that will return the selected file

Regards,
Meghana
Thu, 2006-03-02 13:26
Joined: 2005-10-06
Forum posts: 13
Re: Search Files in Subdirectories
Hi,
   I am not able to select the file from the displayed list.
Please Help

Regards,
Meghana

  • Login to reply to this topic.