Creating directory as well when saving screenshot

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
easy
Posts: 14
Joined: Thu Dec 09, 2010 11:14 am
Location: Hungary

Creating directory as well when saving screenshot

Post by easy »

Hello!

Am I doing something wrong or Irrlicht really does not create the directory as well as the file itself when saving a screenshot?

The way I do it currently is:

Code: Select all

//! createScreenshot
void CGame::createScreenshot()
{
    io::IFileSystem* fsys = device->getFileSystem();
    io::path fbase = "screenshots/screenshot", fext = ".png";
    bool leave = false;
    int num = 0;

    do
    {
        io::path fname, fnum;
        fnum += num;
        fname = fbase;
        fname += fnum;
        fname += fext;

        // check if the screenshot already exists
        if (!fsys->existFile(fname))
        {
            video::IImage* screenshot = driver->createScreenShot();
            core::stringw log;

            if (driver->writeImageToFile(screenshot, fname))
            {
                log = fname;
                log += " has been created";
            }
            else
            {
                log = "Could not create ";
                log += fname;
            }

            screenshot->drop();
            iface->setScreenLog(log);
            leave = true;
        }

        if (++num >= 100) leave = true;
    }
    while (!leave);
}
Basically the code above just wants to save a screenshot to the "screenshots/" directory, with the name of "screenshot<number>.png", and it works fine if I manually create the "screenshots/" directory.

The question is, shouldn't it create the directory too if it doesn't exists?
As I see it, it's the "writeImageToFile" function where it fails.
Oh, and I'm on Ubuntu linux, if that matters.

Thanks your answers in advance,
easy (formely known as PI)
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Irrlich thas no functionality to create directories, nor to remove files or directories.
easy
Posts: 14
Joined: Thu Dec 09, 2010 11:14 am
Location: Hungary

Post by easy »

Allright, thanks for your answer, Hybrid! :)
Post Reply