I am trying to create a class that scans a directory to find which files are in it and return the value as a string. But I can't convert the value of "value2" back to a string. How can I do this?
Thank you Hammurabi. Here is what I've been able to come up with so far. The only problem that I'm having with it now is that "." and ".." show up in the resulting string. I would like to get rid of those.
#include "home.h"
string Templates::getTemplates()
{
string all_templates; //Set the string that will be returned
char *home_path;
home_path = getenv("USERPROFILE"); //Get the user's home directory
string home = home_path; //Convert to std::string
string template_path = home + "\\Templates"; //Add Templates directory to the end of home directory
constchar *template_dir = template_path.c_str(); //Convert back to a const char
DIR *directory = NULL;
directory = opendir(template_dir); //Open the resulting directory
struct dirent *entry = NULL;
if (directory == NULL)
{
}
while (entry = readdir(directory))
{
if (entry == NULL)
{
}
all_templates = all_templates + entry->d_name + "\n"; //Add all the values into one string
}
closedir (directory);
return all_templates;
}