Sign in to follow this  
arbuckle911

generating screenshot file names

Recommended Posts

I'm writting a game in C++/oGL, I need to be able to take screenshots. The actual writting the .bmp file is np, but I have no clue how to do the Screenshot0001.bmp Screenshot0002.bmp Screenshot0003.bmp Screenshot0004.bmp.... Rather than just keep a list I want to be able to something like "GetListOfFileIesFolder("Screens");" Is there a way to do that in C++?

Share this post


Link to post
Share on other sites
Here's an example of how to list files in a directory. After you've done this, you can parse the filenames and create a new filename based on that information. (Windows)

Share this post


Link to post
Share on other sites
You can just do something like this if you don't want to rely on operating system libraries:


int num = 1;
string name = "Screenshot";
string extension = ".bmp";
//find the next available filename
string fileName;
while(true)
{
fileName = name + num + extension;
fstream file(fileName.c_str(), ios::in);
if(!file.is_open())
break;
//no need to close the file, it will be done automagically
}
//good, now we can open it and actually use it
fstream file(fileName, ios::out | ios::binary);
file.write(...);






EDIT: I was being fast and loose, you cant actually do fileName = name + num + extension; Consider it as pseudo-code :-)

[Edited by - deathkrush on June 12, 2006 3:00:17 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this