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.
Page Index Toggle Pages: 1
relative paths (Read 476 times)
relative paths
Mar 10th, 2009, 11:56am
 
sorry for the super-basic question.
relative paths do not seem to work here (osx 10.5, processing 1.0.3)

I tried to do:

import java.io.File;
String pathToMovies = ("/");
String pathToHTML = ("/snip/");
String myDirectory[];

File dir = new File(pathToMovies);  
myDirectory = dir.list();

Processing now realizes ("/") as / in absolute paths and points to the system folder, not to the same folder as the sketch is.

Any suggestions?
Thank you very much!



Re: relative paths
Reply #1 - Mar 10th, 2009, 1:44pm
 
Well, that's not relative paths, precisely: on Unix systems, absolute paths start with / while relative paths... don't!

Current dir would be rather ".", for example.

But on my system at least (Windows XP), dot refers, without much surprise, to location of Processing.exe (the runtime).

There is a little known variable (found in PApplet.java source): sketchPath, which gives you the path to the sketch, which is probably what you want.

Code:
String pathToMovies = sketchPath;
String pathToHTML = sketchPath + "/files";
String[] myDirectory;

File dir = new File(pathToMovies);
myDirectory = dir.list();
println(myDirectory);
dir = new File(pathToHTML);
myDirectory = dir.list();
println(myDirectory);
Re: relative paths
Reply #2 - Mar 10th, 2009, 2:07pm
 
Thanks PhiLho!

Good suggestion! I have tried this now, but sketchPath returns null...
I have imported processing.core.*;

Do you know, what I am doing wrong?
Re: relative paths
Reply #3 - Mar 10th, 2009, 2:11pm
 
sorry PhiLho,

if I put

pathToMovies = sketchPath + "/movies/";

into the setup() block, it works. I have made the mistake
of putting it above the block, where global variables are declared.
Now its working!
Thank you very much for your help!
Page Index Toggle Pages: 1