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.
Code:
/* Steven Billington - not original author
December 10, 2002
Main.cpp
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)
{
find_files();
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: ";
cin>>str;
/* Outout empty line*/
cout<<"\n";
/* Indicates we want mp3 files*/
str += "\\*.mp3*";
/* Find first file*/
HANDLE hFile = FindFirstFile(str.c_str(),&wfd);
/* Aborts on error*/
if(hFile ==INVALID_HANDLE_VALUE)
{
cout << "Directory named " << wfd.cFileName << " found!";
cout << "Error!! Aborting" << endl;
return 1;
}
do
{
/* out files*/
cout<<wfd.cFileName<<endl;
/* Increment counter*/
i++;
}
/* Get the rest of the files*/
while(FindNextFile(hFile,&wfd));
/* Output # of found files*/
cout<<"\nFound "<<i<<" Files.\n"<<endl;
/* Clean up*/
FindClose(hFile);
return 0;
}
/*
OUPUT
______________________________
Enter Directory: c:
Directory named ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦_? found!Error!! Aborting
Press any key to continue
*/