Searching a directory for specific items

Hello,
I have created a small program to migrate user accounts from one domain to another and I would like to place an if/else section in my code to look for certain errors. For instance, when my program prompts for a username, if the users account is not found (searching in -> c:\documents and settings\), I would like the program to let the user know that he/she needs to input the username again.

Because we are going to *possibly* run this on hundreds of machines, I cannot tell my program what specific user profiles to look for. I am guessing I need to use a wild card...but not quite sure if this will work when trying to matchup input from a user to a profile on the PC?

I am not looking for anyone to write this code for me, but if anyone has any ideas on how I might accomplish this it would be appreciated.

We are in a Windows environment.

Thanks!
MSDN says
FindFirstFile Function

Searches a directory for a file or subdirectory with a name that matches a specific name (or partial name if wildcards are used).


See also FindNextFile, FindClose.
I had once made a function to find whether a file/directory exists:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// #included <dirent.h> and <string>
bool exists(string path, string name)
{
    static DIR *Dir;
    static dirent *DirEntry;
    static string fname;

    Dir = opendir(path.c_str());

    while(DirEntry=readdir(Dir))
    {
        fname=string(DirEntry->d_name);
        if (fname==name) return true;
     }
    return false;
}
Last edited on
Topic archived. No new replies allowed.