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 › reading in names of image files
Page Index Toggle Pages: 1
reading in names of image files (Read 493 times)
reading in names of image files
Nov 2nd, 2008, 6:22pm
 
I'm making a program that allows users to load their own images into it.  The plan is to have a user image folder and everything inside that folder is loaded into the program at setup().  The problem I'm having is that not knowing what the names of the images are, the only way I can get it to work is to force the users to rename their images tex1,tex2,tex3...ect.  Does anyone know a way for processing to read in the images without knowing what there names are ahead of time,such as scanning the folder?
Re: reading in names of image files
Reply #1 - Nov 3rd, 2008, 8:07am
 
See, for example, Re: Help with color averaging multiple image files for a method to list files in a directory.
Re: reading in names of image files
Reply #2 - Nov 3rd, 2008, 6:10pm
 
Thanks PhiLho that solved one problem but in implementing the code I ran into another.  This might be a stupid question but I can't seem to get the relative pathname to work with the example.  This code works if I put in the absolute pathname leading to the image folder, but that kills the portability and usability of the code. I'm guessing there has to be an easy work around but I have very limited experience in this area.

//userimages is a directory in the data folder
String source= "userimages";
File dir= new File(source);
PImage srcImg[];
void setup(){
 srcImg=new PImage[100];
 size(500,500);
 if(dir.isDirectory()) {
   File[] fs= dir.listFiles();
   for(int i=0; i< fs.length; i++) {
     srcImg[i] =  loadImage(source+"/"+fs[i].getName());
   }
 }
}
Page Index Toggle Pages: 1