Cannot create new file with ofSystemSaveDialog()

Hi.

I want to create a NEW file with ofSystemSaveDialog() in the following code. When I press the ‘s’ key, the save dialog is displayed and input filename and press the Enter key…However, the file is not created. Is there another effective option? Or is the function NOT for create NEW file? What’s wrong?

ofApp.h

ofFileDialogResult hoge;

ofApp.c

void ofApp::keyPressed(int key){
    if(key == 's'){
        hoge = ofSystemSaveDialog("hoge.txt", "Where to save?");
    }
}

Environment

  • Windows 10 Home

  • Microsoft Visual Studio Community 2015 Version 14.0.25431.01 Update 3

  • openFrameworks 0.9.8

that function only opens the dialog and returns an ofFileDialogResult but it won’t create any file. it’s up to you to read the path in ofFileDialogResult and create a file there. if the path is empty that means that the user has pressed cancel and you shouldn’t create any file then.

eg:

void ofApp::keyPressed(int key){
    if(key == 's'){
        hoge = ofSystemSaveDialog("hoge.txt", "Where to save?");
        if(hoge.path!=""){
            ofFile file(path, ofFile::WriteOnly);
            // write something to the file here
        }
    }
}
2 Likes

thanks a lot!

1 Like