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 › Listing image files names
Page Index Toggle Pages: 1
Listing image files names (Read 522 times)
Listing image files names
May 28th, 2008, 9:52pm
 
Is there a way of listing the names of image files in a specific folder?

I couldn't find out how to do it....

Thanks
Re: Listing image files names
Reply #1 - May 28th, 2008, 10:27pm
 
This is the third time this has been asked (and answered twice) in the past week. Is this homework somewhere?
Re: Listing image files names
Reply #2 - May 28th, 2008, 11:08pm
 
Not for me...

I just couldn't find in the search engine... (maybe I didn't use the proper key words...)

could u pass me the link of the post?
Re: Listing image files names
Reply #3 - May 29th, 2008, 6:48am
 
The How to get the number of files in a folder and shows a code snippet exactly what you look for.
Re: Listing image files names
Reply #4 - May 29th, 2008, 11:36am
 
Hi! I have a class that read only image from a directory ( relative to sketch folder ) and read all colour picture data.

this is the function that read the list
Quote:


/*METODOS PRIVADOS-----------------------------------------------------------------*/
 private String [] leerDirectorio(String _path){
   if (isDir) {
     dir = new File(dataPath(_path));  
   }
   else
   {
     dir = new File(_path);  
   }
   String[] children =  dir.list(new PicFilter());
   if (children == null) {
     //println("*******  error en la lectura del directorio >>"+_path);
   }  
   else {
     //println("*******  list >>"+_path +"children.length:"+children.length);    
     for (int i=0; i<children.length; i++) {
       children[i] = _path + children[i];
       println("*******  paleta["+i+"] >>"+children[i]);  
     }
   }  
   return children;

 }



I had to use some java functions, copy here , If someone thinks that this  class could be better, please, say me!

here are the entire class and example!

www.openprocessing.org/visuals/?visualID=257




best regards. Alba


Re: Listing image files names
Reply #5 - May 30th, 2008, 2:33am
 
in which library is PicFilter ()? java.io?

Re: Listing image files names
Reply #6 - May 30th, 2008, 10:31am
 
PicFilter is an implements from import java.io.FilenameFilter

Smiley


you can view an example here

http://www.java2s.com/Code/JavaAPI/java.io/implementsFilenameFilter.htm


Quote:

/**
* filter out PICS .Changed by Alba G. Corral
*/
class PicFilter implements FilenameFilter
{

/**
  * Select only *.Pic files.
  *
  * @param dir the directory in which the file was found.
  *
  * @param name the name of the file
  *
  * @return true if and only if the name should be
  * included in the file list; false otherwise.
  */
 public boolean accept ( File dir, String name )
 {
   if ( new File( dir, name ).isDirectory() )
   {
     return false;
   }
   name = name.toLowerCase();
   return (name.endsWith( ".png" ) || name.endsWith( ".jpg" ) || name.endsWith( ".gif" )) ;
 }
}

Page Index Toggle Pages: 1