Thread: Worked, then made it a function: Console

  1. #1
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002

    Worked, then made it a function: Console

    Ok, i used demo code someone gave me in the main and it worked. It searched for mp3 files fine, and listed them as well as how many. Then i made the code its own function, and called that function in main. I know its something i did wrong, the code is below, and at the bottom of the code is the output commented off within the program. I have included all of the code, so u can see how i called it and whats going on.

    /*	Steven Billington - not original author
    	December 10, 2002
    	Program searches the given directory for any
    	file ending in the .mp3 extension. It will not
    	check to ensure these are genuine mp3 files, 
    	it will just report them as such based on the
    	files extension. If you save a text document 
    	with a .mp3 extension, for example, it will 
    	recognize this as a mp3 file in its search.
    	See readme for details.
    /*	Our preprocessor Directives*/
    #include <iostream>
    #include <windows.h>
    #include <string>
    int find_files();
    /*	Define our STD's*/
    using std::string;
    using std::cout;
    using std::cin;
    using std::endl;
    int main(int argc,char** argv)
    	return 0;
    int find_files()
    	/*	Holds information found*/
    	WIN32_FIND_DATA wfd;
    	/*	Holds directory*/
    	string str;
    	/*	Counts files found*/
    	int i = 0;
    	/*	Prompt user for directory*/
    	cout << "Enter Directory: ";
    	/*	Outout empty line*/
    	/*	Indicates we want mp3 files*/
    	str += "\\*.mp3*";
    	/*	Find first file*/	
    	HANDLE hFile =  FindFirstFile(str.c_str(),&wfd);
    	/*	Aborts on error*/
    		cout << "Directory named " << wfd.cFileName << " found!";
    		cout << "Error!! Aborting" << endl;
    		return 1;
    		/*	out files*/
    		/*	Increment counter*/
    	/*	Get the rest of the files*/
    	/*	Output # of found files*/
    	cout<<"\nFound "<<i<<" Files.\n"<<endl;
    	/*	Clean up*/
    	return 0;
    Enter Directory: c:
    Directory named 
    _? found!Error!! Aborting
    Press any key to continue

  2. #2
    Registered User
    Join Date
    Apr 2002
    The code worked ok for me ?? Now I got your output if there was no MP3 in the given directory for C: . But if I put a mp3 in C: it worked perfectly. Also if you get an invalid HFILE you should probably just say File Not Found or some such and output the string the user entered for the path it wasn't in. Good luck.

  3. #3
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    ooo someone took the mp3 file i was using for test off of the c (prolly me lol).

    thnx man.

  4. #4
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    ya i fixed that, the whole if now just couts an error and returns one. Like i said i didn't write it originally i'm just imporiving it.

    As for the str line, its always empty now because i placed

    str = "";

    after its declaration, then made (for what type if file to look for) a new variable, ext, also a string.

    now the user inputs the type of file they want in format of *.ext* and hits enter.

    then it reads in that and adds \\ to it via

    ext = "\\" + ext;

    and finally the new str line is

    str += ext;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM