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 › check if a file is in a folder
Page Index Toggle Pages: 1
check if a file is in a folder? (Read 1465 times)
check if a file is in a folder?
Apr 6th, 2010, 11:44am
 
Hello

Anyone knows how to use processing to check if a file is in a folder? I have looked around and couldn't find anything

thanks in adv
P

Re: check if a file is in a folder?
Reply #1 - Apr 7th, 2010, 12:05am
 
Well one option is to use the listing files hack and then test each filename in the folder...

Unfortunately the hacks seem to be hidden away; though some might argue this is a good thing as not everything there is good practice or up-to-date...
Re: check if a file is in a folder?
Reply #2 - Apr 7th, 2010, 5:28am
 
Code:
File file = new File(filePath);
if (file.exists())
{
println("I found it!");
}
Re: check if a file is in a folder?
Reply #3 - Apr 8th, 2010, 4:33pm
 
Quote:
Unfortunately the hacks seem to be hidden away;


Ya, its maybe not the best place to raise that, but that's imo an issue you point out... i mean why is the hacks thingie so well hidden? Shouldnt it have it's place at least somewhere in the tabs of this site? Anyone?
Re: check if a file is in a folder?
Reply #4 - Apr 9th, 2010, 12:25am
 
Oh! First time I came across the hacks... (..which maybe prooves the point...) Thanks for telling me.
Re: check if a file is in a folder?
Reply #5 - Apr 18th, 2010, 9:46am
 
PhiLho  wrote on Apr 7th, 2010, 5:28am:
Code:
File file = new File(filePath);
if (file.exists())
{
 println("I found it!");
}



Thanks for providing me with your code.

I couldn't make it work. please help me!

Here is my code

File file = new File(dataPath("drawing.mov"));
     if (file.exists()) {
    println("I found it");
}

I have both processing file and drawing.mov file in the same folder, when I run the application, I should receive "I found it" message; but I didn't receive anything. Am I missing something here?

thanks
Re: check if a file is in a folder?
Reply #6 - Apr 18th, 2010, 11:21am
 
dataPath, by definition, provides the path to the data folder. Use sketchPath() (from memory).
Re: check if a file is in a folder?
Reply #7 - Apr 18th, 2010, 11:40am
 
Thank you very much, I got it

by the way.. where can I find my data folder?


Re: check if a file is in a folder?
Reply #8 - Apr 18th, 2010, 1:03pm
 
pandean wrote on Apr 18th, 2010, 11:40am:
Thank you very much, I got it

by the way.. where can I find my data folder


IIRC the data folder is only created when data is added to the sketch (i.e. using the Sketch > add File menu option).  You'll then find a data folder within your sketch folder.  Be careful though as this is then compiled into the .JAR file when you export your sketch - so it's not something that is usually accessible to people running your sketch...  It's just a handy repository for files needed to run the sketch (e.g. fonts).
Page Index Toggle Pages: 1