I want to be able to put all the file names of a specific extension into a string array so i can load them into my program.
How dose that work?
I want to be able to put all the file names of a specific extension into a string array so i can load them into my program.
How dose that work?
have to use a file search of some sort...then maybe build a data base...
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
If you're doing this in WIN32API look up the functions FindFirstFile
and FindNextFile in the Help or in a book.
> I want to be able to put all the file names of a specific extension into a string array
Well the way you find filenames is by using
For DOS/Windows
findfirst and findnext
You'll need to look up the exact names, there are several variants, depending on which specific MS OS you have
For Unix/Linux
opendir, readdir, closedir are the functions you want
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.
I looked it up on MSDN, and im still not quite getting it.
I tried something like this, but it just crashes the program when it runs.
WIN32_FIND_DATA * data;
FindFirstFile("*.txt",data);
filename = data->cFileName;
if filename is a char* you will need to use strcpy() instead of = .
secondly salem has posted an excellent directory walker at least twice.A search will throw that up.You will learn much from that small piece of code.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
> WIN32_FIND_DATA * data;
> FindFirstFile("*.txt",data);
That's because you should have written...
WIN32_FIND_DATA data;
FindFirstFile("*.txt", &data);
When something takes a * parameter, it's not good enough to simply declare a variable of that type, you've got to make sure it points somewhere.
Or, you declare a variable without the *, and you pass &var to the function instead.
> secondly salem has posted an excellent directory walker at least twice.
*blush*
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.