Archived

This topic is now archived and is closed to further replies.

DanTheRocker

Searching directories

Recommended Posts

I''m trying to figure something out, and I think I''m close to the solution, but can''t quite get it right. There is a folder in my computer, D:\MP3, and it contains a bunch of sub folders that all contain my mp3 files. The mp3 player that I''m making is able to search the D:\MP3 folder, but I can''t figure out how to get it to search all the sub folders along with it. How would I do this? Should I still use _findfirst() and _findnext(), or is there a better way? If you have dont something like this in a project of your own, I''d like to see how you did it.

Share this post


Link to post
Share on other sites
Well, _findfirst and _findnext are just fine I think.
You´ll just have to write a routine that searches a directory for other dir´s. if the routine find´s one it will have to chdir into it and then call itself:

int search_dir()
{
find_mp3_in_this_dir();

for( all directories i can find)
{
change_to( directory i found );
search_dir();
}
}


Share this post


Link to post
Share on other sites
Ok, I''ve made a lot of progress, but one thing is stumping me. I''ll simplified example of my problem:

First I set
SetCurrentDirectory( "D:\\MP3\\" );
Which works.
It then looks for all the mp3''s in this directory and adds them
to a list box. Which also works.
After that it searches for all directories in this directory, and when it finds one, sets the current directory to it and then scans that directory for all mp3''s. The process repeats until all folders and subfolders have been scanned. This works too. However my problem is getting it to go back to "D:\\MP3\\" after it has finished searching. Is there some text command that simply moves back one directory?
Basically if I say:
SetCurrentDirectory( "D:\\MP3\\Led Zepplin" );
how do i get it to set the directory to "D:\\MP3\\" again.(without hard coding "D:\\MP3\\" into the code after each search.
I hope this made some sence....thanks for reading.

Share this post


Link to post
Share on other sites