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 › Scanning a directory for a given file extension
Page Index Toggle Pages: 1
Scanning a directory for a given file extension (Read 539 times)
Scanning a directory for a given file extension
Jul 1st, 2009, 9:54am
 
Does anyone have any examples of how I might go about scanning a directory for a given file extension in processing?  I could run the following from a command prompt:
dir > files.txt
and then parse the text file as a workaround, but I'd rather set up my sketch to read the directories contents at run time.  Thanks in advance,

-B
Re: Scanning a directory for a given file extension
Reply #1 - Jul 1st, 2009, 11:09am
 
no idea if this'll work in processing, almost certainly won't work in applet mode

http://www.exampledepot.com/egs/java.io/GetFiles.html

java's File.list and FilenameFilter basically.
Re: Scanning a directory for a given file extension
Reply #2 - Jul 1st, 2009, 12:46pm
 
Thanks for the quick response.  The following code works
   
File dir = new File("C:\\MyFileFolder\\");
   
   String[] children = dir.list();
   if (children == null) {
       // Either dir does not exist or is not a directory
   } else {
       for (int i=0; i<children.length; i++) {
           // Get filename of file or directory
           String filename = children[i];
       }
   }
Page Index Toggle Pages: 1