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 & HelpPrograms › Function to get file location
Page Index Toggle Pages: 1
Function to get file location (Read 1011 times)
Function to get file location
Jan 19th, 2010, 4:39pm
 
Hello
Is there some function in processing that goes and get the processing file location?
Like it would return the string C:/Users/USER/Documents/Processing/filename
This would be really helpful, cause like this i wouldnt be constantly having to change the code everytime i change computer or file location.

Any help would be greatly appreciated! Smiley
Re: Function to get file location
Reply #1 - Jan 19th, 2010, 7:12pm
 
Any help?
Re: Function to get file location
Reply #2 - Jan 19th, 2010, 11:24pm
 
Use sketchPath() and dataPath() to get the location of the sketch and data folders.  Both take a string argument - the intention being that you're most likely to need the path to access a file.  Pass an empty string to get just the path; though I suspect this won't be necessary if you use them correctly:

Code:
String filename = "image.jpg";
// assuming the image is in your data folder:
String imagePath = dataPath(filename);
println(imagePath);


Re: Function to get file location
Reply #3 - Jan 20th, 2010, 2:03am
 
blindfish wrote on Jan 19th, 2010, 11:24pm:
Pass an empty string to get just the path

Actually, as I recently (re-)discovered, we have sketchPath variable for that. Smiley
Re: Function to get file location
Reply #4 - Jan 20th, 2010, 3:03am
 
I guess that's documented over on the development reference?  I really should have a dig round that more often!
Page Index Toggle Pages: 1