Hi all.
I was writing this program to search for/ list files, and I came across a rather annoying problem. I'll post the code first:
Code:
#include <windows.h>
#include <iostream>
#include <conio.h>
#include <string>
#include <fstream>
#include <process.h>
using namespace std;
#define nul '\0'
char Stop_Search = nul;
void KeyCheck (void *);
bool Search_For_Specified_File();
bool LAFOAST ();
int main()
{
char Menu_Selection;
cout<<"\n\n\n Welcome to the File Locater. This program is able to find and list all\n"
" files of a specified type, and can be useful if you wish to check for a\n"
" file existance.\n\n Do you wish to:\n\n"
" 1. Search for a specified file.\n"
" 2. List all files of a specified type.\n\n"
" Number of desired selection: ";
Menu_Selection = getch();
while ( Menu_Selection != '1' && Menu_Selection != '2')
{
Menu_Selection = getch();
}
cout<< Menu_Selection;
Sleep(2000);
system("cls");
switch (Menu_Selection)
{
case '1':
cout<<"\n\n\n Search for specified file function goes here.";
Sleep(2000);
break;
case '2':
LAFOAST();
break;
default:
cout<<"\n\n\n Unknown error has occured.\n Execution terminated.";
Sleep(2000);
break;
}
}
bool LAFOAST ()
{
char Search_Filename = nul;
string Filename;
string Extension;
int Files_Found = 0;
int Character_Number = 0;
cout<<"\n\n\n Please input the extension of files you wish to list.\n"
" If you wish to list all files, leave the following form blank.\n\n"
" File Extension: ";
getline(cin, Extension);
system("cls");
cout<<"\n\n\n Beginning search...\n"
" Press any key to terminate the search.\n\n\n ";
_beginthread( KeyCheck, 0, NULL );
Sleep(2000);
while (Stop_Search == nul)
{
Filename = Extension;
ifstream Read (Filename.c_str());
if (Read.is_open())
{
cout<<Filename<<"\n ";
Files_Found++;
}
Search_Filename++;
Character_Number++;
reverse(Filename.begin(), Filename.end());
Filename += Search_Filename;
reverse(Filename.begin(), Filename.end());
Filename = "";
}
cout<<"\n Search Successful\n Press any key to quit.\n\n ";
char Quit_Input;
Quit_Input = getch();
}
////////////////////////////////////////////////////////////////////////////////
void KeyCheck (void *P)
{
Stop_Search = getch();
}
My problem is the while loop in LAFOAST. As you probably could have guessed, I'm trying to check the existance of files, by trying all possible combinations until the user stops the search. Trouble is, it checks every combination of one character, followed by the designated extension, then does it again. Is there a way of adding a character infront of the constantly changing one, that changes every time the changing one reaches the final character?
I can't for the life of me, think of a way to do this by adding to the while loop. Is this possible?
Any help greatly appriciated.
Necrofear.