Jump to content
  • Advertisement
Sign in to follow this  
DominicHughes

trying to read all filenames from cmd?

This topic is 2468 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I've got this code here that lists out the filename for every .txt extension found and I want to get all these filenames and store it in something that I can use as a path later on for when I go to read from it

I'm using Boost Iostreams and Boost Filesystems

here is my current code



path p = "textfolder";


try
{
for (directory_iterator it(p); it != directory_iterator(); ++it)
{
//cout << *it << endl;

if(extension(*it) == ".txt")
{
// cout << ".txt found" << endl;

cout << it->path().filename() << endl;

// NEED TO STORE EACH ENTRY OF A FILENAME INTO A STRING
// THEN READ EACH STRING AS A FILENAME OR READ THE STRING
}


}
}

catch (const filesystem_error& ex)
{
// cout << ex.what() << endl;
}

}


I've tried using cin.getline and other methods like


sprintf(*it->path().filename(), "%s");
printf("%s", *it->path().filename(), output);


cin.getline(buffer, 500, delim);
cout << buffer << endl;



Non of which have gave me successfull results

Share this post


Link to post
Share on other sites
Advertisement
Store all the *.txt files in a vector of strings?


std::vector<std::string> TextFilenames;
...
if (extension (*it) == ".txt") {
TextFilenames.push_back(it->path().filename());
}


When you've finished finding all the files in that path, you'll have TextFilenames.size() number of .txt files. You can then loop through each.

Or, am i missing something?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!