Darzen
Darzen

Reputation: 1165

Not able to create temp file in the desired directory

I need to create a temp file in a specified folder on MAC. However I am able to create the folder at the correct location but not able to create the file inside. I get an error saying it does not have permissions to create the file although i have passed 777 as file permission while creating the folder. please find my code below. I would like to mention that this problem is only on MAC. On windows it executes as expected. please let me know what the issue is.

    wxString curDir = SeeWorkingDir() + wxT("Temp\\"); //Gets the working directory

    if(!wxFileName::DirExists(curDir)) //Checks if directory exists
    wxFileName::Mkdir( curDir, 0777, wxPATH_MKDIR_FULL ); // creates the directory

    wxString jobcopy = wxFileName::CreateTempFileName(curDir); // should create temp file

Upvotes: 0

Views: 537

Answers (2)

PauliL
PauliL

Reputation: 1269

You have not explained what your function SeeWorkingDir() does.

Maybe you should use wxFileName::GetTempDir to specify the directory where you store the file. This should be platform independent.

Or, in your call wxFileName::CreateTempFileName(curDir), you could specify the fileTemp parameter to open the file directly.

See the documentation: wxWidgets 2.8.12 - wxFileName

Upvotes: 0

Michael Dautermann
Michael Dautermann

Reputation: 89519

I have absolutely no idea what your "SeeWorkingDir()" function is returning, but if it's returning the application directory then you shouldn't be writing anything into there.

Why not replace "SeeWorkingDir()" with a path to somewhere on the Macintosh that truly is writable, like the "/tmp/" directory?

Upvotes: 1

Related Questions