Thread: Directory MP3 Search

  1. #1
    Young C n00b
    Join Date
    Jul 2006
    Posts
    59

    Directory MP3 Search

    Hi guys, i've got myself in a bit of a jam. I'm in an 'intro to C++' class. My professor is a first time teacher. He's a great programmer, but frankly, he sucks at teaching. He's already trying to teach us windows programming and not even one person in the class has an idea of what's going on (half of the class doesn't even know what a function is!!).

    We have a project due wednesday. The project is to develop an application that can search a windows directory (and subdirectories) for mp3s and display the paths of the mp3 files that are found.

    I'm not exactly sure how to go about doing this. The obvious solution would be to read read read, but I can't learn windows programming by wednesday.

    So my question is would anyone be willing to kind of walk me through designing an application like this? I'd imagine i'd need to write some type of recursive function to do the actual searching..

    How do I have windows go to a certain directory?
    How could I write a function that searches the current directory for an mp3 file?


    Thanks for any help, i'm really stuck on this.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Mmm, have you ever considered reading the FAQ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Young C n00b
    Join Date
    Jul 2006
    Posts
    59
    I was asking for some one-to-one help, not a reference to an FAQ. Windows programming is far beyond my skill level so I wouldn't make good use of an FAQ. I'd need help from someone to explain it a little to me, or at least a detailed tutorial.

  4. #4
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    You don't need to use windows programming to find the file. As for the GUI, have you looked at the link at the top of the board?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Reading files from the file system isn't a GUI problem.

    Displaying the filenames might be a GUI problem, depending on how you do it.

    You seemed to be lost on step 1, nevermind step 2.

    So post some actual code of what you can and cannot achieve if you want better answers in future.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Young C n00b
    Join Date
    Jul 2006
    Posts
    59
    this is what i've got so far. I'm currently only interested in programming option 1 of the menu.


    Code:
    #include "stdafx.h"
    #include <iostream>
    using std::cout;
    using std::endl;
    using std::cin;
    #include <string>
    using std::string;
    
    //prototypes
    void mainMenu();
    void inputDirectory();
    void undefined();
    
    
    //global data
    int menuSelection = 0;
    string directoryToSearch;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    
    	mainMenu();
    	return 0;
    }
    
    void mainMenu()
    {
    system("cls");
    
    	cout << "\t\t\tWelcome to Kyle's MP3 Tool." << endl
    		 << "\t\tSelect a menu option  ( 1 - 4)" << endl
    		 << "\n\n\n(1) ~~> Scan a directory to build a playlist of MP3s" << endl
    		 << "(2) ~~> Filter playlist" << endl
    		 << "(3) ~~> Save a playlist of MP3s" << endl
    		 << "(4) ~~> Load a playlist of MP3s" << endl
    		 << "(5) ~~> Play a playlist of MP3s\n\n\n" << endl;
    
    	int x = 1;
    	while (x == 1)
    	{
    		cin >> menuSelection;
    
    		if (menuSelection >= 1 &&
    			menuSelection <= 5)
    			x = 0;
    		else 
    			cout << "Invalid menu selection. Try again." << endl;
    	} //end while loop
    
    	switch(menuSelection)
    	{
    	case 1:
    		inputDirectory();
    		break;
    	case 2:
    		undefined();
    		break;
    	case 3:
    		undefined();
    		break;
    	case 4:
    		undefined();
    		break;
    	case 5:
    		undefined();
    		break;
    	} //end switch statement
    
    } //end mainMenu
    
    
    void inputDirectory()
    {
    	cout << "Enter a directory to search. All subdirectories will also be searched." << endl
    		<< "Example:   C:\\Music\n" << endl;
    	cin >> directoryToSearch;
    	cout << "\nDirectory Entered: " << directoryToSearch << endl;
    }
    
    void undefined()
    {
    cout << "This function is under construction.\n" << endl;
    for(long stall = 0; stall < 350000000; stall++); //stalls the computer so the user can see the message
    
    mainMenu();
    }

  7. #7
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Can you deal with this code from the FAQ?

    Code:
    HANDLE          h;
    WIN32_FIND_DATA info;
    
    h = FindFirstFile("*.*", &info);
    if (h != INVALID_HANDLE_VALUE)
    {
        do
        {
            if (!(strcmp(info.cFileName, ".") == 0 || strcmp(info.cFileName, "..") == 0))
            {
                // do additional processing to see if file extension is .mp3 or something
            }
        } while (FindNextFile(h, &info));
        FindClose(h);
    }
    I didn't see you mention it, but manutd mentioned something about a GUI. Do you need one for this project?

  8. #8
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    I assumed by windows programming he meant he had to use a GUI Obviously not, but other than that, what "windows programming" would he have to do for this assignment?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  9. #9
    Young C n00b
    Join Date
    Jul 2006
    Posts
    59
    ok i did some reading and i learned a bit about the WIN32_DATA_FIND.

    So what I'm guessing is that i'll have to declare an object of the WIN32_DATA_FIND structure, then call functions from it.

    What header files will I need to include?
    Where can I learn more about HANDLES?

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You can lead a horse to water, but you can't make him think.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by kwikness
    What header files will I need to include?
    Where can I learn more about HANDLES?
    msdn.microsoft.com
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  12. #12
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Where can I learn more about HANDLES?
    HANDLE, like any other windows data type (HWND, HINSTANCE, HBRUSH) is an int, but has been given such name, so you could easily recognize it in some piece of code.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  13. #13
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    has been given such name, so you could easily recognize it in some piece of code.
    Actually it gives a microsoft a possibility to change the int to some other type in the future, and no need to make changes in the code using windows API
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  14. #14
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    That too, but if that would be the only reason, the would've just made one APIINT or something.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  15. #15
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by maxorator
    HANDLE, like any other windows data type (HWND, HINSTANCE, HBRUSH) is an int, but has been given such name, so you could easily recognize it in some piece of code.

    Is that a int, int32 or int64?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can i check a directory for certain files?
    By patrioticpar883 in forum C++ Programming
    Replies: 13
    Last Post: 02-01-2008, 05:27 PM
  2. Finding files in a directory
    By smarta_982002 in forum C Programming
    Replies: 1
    Last Post: 01-25-2008, 10:10 AM
  3. Search For a Directory
    By IdioticCreation in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2007, 02:53 PM
  4. Simple search program
    By colinuk in forum C Programming
    Replies: 6
    Last Post: 12-18-2004, 01:58 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM