0

I started working with some files, something easy.

I read that the File class support relative paths, so I tried something like:

File file_bg = new File("data\\bg.png"); if(file_bg.exists()) flag_bg = true; 

Ok, now, making some debugging I noticed that every File variable have as parent path the same path where the IDE is, instead of the path where my project is.

Is it a common behavior or I have to set up something before starting the sketch? Is it equal for java IDEs like NetBeans?

One more question, there is a way to keep a String variable in memory that contains the path of my .pde file?

Thanks a lot for the interest, waiting a response!

2

1 Answer 1

2

You don't need to store a string with that directory, Processing can give it to you with sketchPath() and dataPath()... Not particularly odd, google's first result for "processing sketch path" returns this

thus:

File file_bg = new File(dataPath("bg.png")); 
Sign up to request clarification or add additional context in comments.

4 Comments

dataPath("") paradoxically doesn't return the data folder of the sketch, but a folder [null\data\ ] inside the IDE folder.
how about sketchPath()? What version of Processing are you using?
also try this hacky slashy method: args[0].split("=")[1]
I am using the last version, 2.1.1. sketchPath() returns the same path of dataPath() without entering in data\ . By now I set the drive folder [is an external hd] with getAbsolutePath().getChar(0) + ":\\"; and then I add the ret of the path statically.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.