For the todo list:
A sample directory walker:
Code:
/*
Note: your compiler may require preceding underscores for some of the functions/constants/data structures used here.
ie: _findfirst or _A_SUBDIR, etc...
*/
#include <dirent.h>
#include <string.h>
#include <iostream>
static char CURRENT_DIRECTORY[1024];
void
Search(const char * folder, const char * substring)
{
DIR * directory = opendir(folder);
if(directory == NULL) return;
chdir(folder);
finddata_t * file = &directory->dd_dta;
long index = findfirst("*", file);
do
{
if(strstr(file->name, substring))
{
if(file->attrib & A_SUBDIR)
cout << " Folder:" << endl;
else
cout << " File:" << endl;
if(file->attrib & A_ARCH)
cout << "(Archive)" << endl;
if(file->attrib & A_SYSTEM)
cout << "(System)" << endl;
if(file->attrib & A_HIDDEN)
cout << "(Hidden)" << endl;
if(file->attrib & A_RDONLY)
cout << "(Read Only)" << endl;
getcwd(CURRENT_DIRECTORY, 1024);
cout << CURRENT_DIRECTORY << "\\" << file->name << endl;
}
if(file->attrib & A_SUBDIR
&& strcmp(file->name, ".") != 0
&& strcmp(file->name, "..") != 0)
{
Search(file->name, substring);
chdir("..");
}
} while(findnext(index, file) == 0);
findclose(index);
closedir(directory);
return;
}
int main()
{
Search("c:\\", "config.sys");
cout << endl << "Finished Searching.";
cin.get();
}
A simple busy wait function:
Code:
#include <time.h>
void wait(unsigned milliseconds)
{
unsigned timeout = clock() + milliseconds;
while( clock() < timeout ) continue;
}
Two handy functions for newbies:
Code:
void say(const char * str, ...)
{
char quote[strlen(str)+1024];
va_list v;
va_start(v, str);
vsprintf(quote, str, v);
int length = strlen(quote);
if(length && length < 80)
{
if(length%2)
++length;
for(int i = 0; i < 40-length/2; ++i)
cout << " ";
cout << quote << endl;
}
cin.get();
}
void affirm(bool condition)
{
if(condition)
say("Yes.");
else
say("No.");
}
int main()
{
int x = 4096;
affirm(x > 4095);
}