Finding files interface
Hi guys i need some help!
How can I find files in an certain file type(say .bmc) in a certain directory?
Is it any such interface/header in MSVC++ include library,
if it exists, what is it called(the header file)?
I want to recieve an char array of existing file names in a directory.
any help apprichiated!
by the way does this work?:
#define MAX_ARRAYS 10
typedef short[MAX_ARRAYS] array;
Anton Karlsson
Klingis Entertainment
Games with silly humor
quote:by the way does this work?:
#define MAX_ARRAYS 10
typedef short[MAX_ARRAYS] array;
no
<windows.h> has the functions "FindFirstFile", "FindNextFile", and "FindClose".
Example code:
[edited by - Beer Hunter on June 3, 2003 4:40:32 AM]
Example code:
#include <windows.h>#include <string>#include <vector>...std::vector<std::string> findFiles(const string& mask){ std::vector<std::string> result; WIN32_FIND_DATA fileData; HANDLE search = FindFirstFile(mask.c_str(), &fileData); if (search == INVALID_HANDLE_VALUE) return result; do { if ((fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) result.push_back(fileData.cFileName); } while (FindNextFile (search, &fileData)); FindClose(search); return result;}...std::vector<std::string> files = findFiles("c:/somewhere/*.txt");
For your other question, try: typedef short array[MAX_ARRAYS];[edited by - Beer Hunter on June 3, 2003 4:40:32 AM]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/findfirstfile.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/findnextfile.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/findnextfile.asp
Can I use a char **array; instead,
cos I want to code in just C.
void find_file_paths(char &**array, char *path){ WIN32_FIND_DATA fileData; HANDLE search = FindFirstFile(path, &fileData); if (search == INVALID_HANDLE_VALUE) return; do { if ((fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) strcpy(*array++, fileData.cFileName); } while (FindNextFile (search, &fileData)); FindClose(search);}char **array;find_file_paths(array);
or
#define MAX_FILE_NAME_LENGTH 64
typedef char *FILE_NAME_ARRAY[MAX_FILE_NAME_LENGTH];
Anyway, I will use a struct made of myself called file_data.
struct file_data
{
short id;
short format;
char *path;
char *name;
char *extension;
};
Is string a typedef char *string; ?
Anton Karlsson
Klingis Entertainment
Games with silly humor
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement