How to get path from working directory and use it?


#1

Hi

I’m sorry for this no-brainer question but I’m having difficulties reading the JUCE documentation.

I want to retrieve the working directory and use it for FileIO handling.

I tried the getCurrentWorkingDirectory() and I expected this to return a string containing the path to my compiled exe-file which I would then concatenate with my filename when creating the file; as such:

static const filePath = File::getCurrentWorkingDirectory(); myFile = new File(String(filePath) + T("temp.txt"));

Unfortunately this doesn’t work.

Can someone please tell me how to do this?

Thanks
Thomas


#2

getCurrentWorkingDirectory() returns a File object representing the directory so you need to get the path name from it first using getCurrentWorkingDirectory().getFullPathName(). You should then be able to concatenate it as you are doing.

You also need to make sure you declare the path as a string:

String filePath = File::getCurrentWorkingDirectory().getFullPathName(); myFile = new File(filePath + T("temp.txt"));

Hope that helps.


#3

Or:


#4

[quote=“jules”]Or:

Thanks a lot for your support guys… this is great!

Thomas