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 › get a filename list from a directory
Page Index Toggle Pages: 1
get a filename list from a directory (Read 581 times)
get a filename list from a directory
Apr 6th, 2006, 8:41am
 
I wish to know how to get the filenames from a directory?.. soo then i can load new files in runtime. Thanks!
Re: get a filename list from a directory
Reply #1 - Apr 6th, 2006, 1:29pm
 
Try this!

You might want to add a filter to return only those files types you want, i.e. ".gif"

Code:



String[] children;
int childCount = 0;
File dir;

void setup() {


dir = new File((System.getProperty("user.home"))+"/yourPath");

children = dir.list();
if (children == null) {
println("-- file not found");
return;

} else {


for (int i=0; i<children.length; i++) {

println (children[i]);
}
}
println(children.length+" files found...");

}


Re: get a filename list from a directory
Reply #2 - Apr 6th, 2006, 2:02pm
 
allright! hey thanks!
..how did you know about this File class?!.. i tryed to search on Processing reference but couldn't find it.
Re: get a filename list from a directory
Reply #3 - Apr 6th, 2006, 3:42pm
 
Look here:

http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html

Processing extends java.applet, which is itself and extension of the java.lang.Object root class (common parent to all Java code):

Here's a link to the package/class overview

http://java.sun.com/j2se/1.4.2/docs/api/index.html

So it's not strictly part of the processing package, hence no reference to it in the docs, but processing can of course use it.

Sorry for the crap explanation.

Look at the FAQ and comparison etc. for more info
Page Index Toggle Pages: 1