How to handle, how can I iterate over files / images in my sketch data directory?

I want to load a bunch of images (or files, but there is no object / type for this) - not by name, but only depending on which of them are in the data directory, in an array or something else, is there a way for this? Documents make it look impossible, and searching on the processing forums does not cause anything. But it is hard to believe that this is an omission.

Any clues? Thank!

+3
source share
1 answer

- , - , Java. , , , , Java , . , , . , :

import java.io.File;

 File dir = new File("folder-with-images");

 File[] files = dir.listFiles();

 for( int i=0; i < files.length; i++ ){ 
   String path = files[i].getAbsolutePath();

   // check the file type and work with jpg/png files
   if( path.toLowerCase().endsWith(".jpg") || path.toLowerCase().endsWith(".png") ) {

     PImage image = loadImage( path );

     //
     // do stuff with your images
     //

   }
 }
}
+3

All Articles