We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Get directory of current sketch
Page Index Toggle Pages: 1
Get directory of current sketch? (Read 633 times)
Get directory of current sketch?
Dec 16th, 2008, 5:01pm
 
I want to access data stored in a folder relative to my current sketch, but I'm having trouble.

Some processing functions like PImage automatically operate in the local sketch directory, but doing something like
dir = new File(folderName);
files = dir.list();
requires an absolute path for folderName.  

System.getProperty("user.dir") will get me the directory Processing is running in, but that is nowhere near where my sketches are.  

In the dev.processing reference area I see there is a Sketch class that has a getCodeFolder() function, is there a way to access Sketch from inside my sketch?
Re: Get directory of current sketch?
Reply #1 - Dec 16th, 2008, 5:31pm
 
sketchPath(""); will give you the path to the sketch, dataPath(""); will give you the path to the data directory.

You can put things into the method to give a file, e.g. sketchPath("foo.txt"); will give you the path to a file called "foo.txt" in the sketch directory.
Page Index Toggle Pages: 1