Updating Number of Files While Sketch Runs

Hello!

I am working on a way to see how many image files are in the sketch folder. My goal is to load the folder with images with an API and as the sketch runs, check to see if new images have been added.

I can imagine my problem is with the static array used to load the string of file names. I just can’t think of a way around it. Would it be to do with something along the lines of folder.length .
How can I get an int for how many files are in a folder?

int maxImages = 15;  //total # of images
int indexCap = 1; //number of images currently in sketch folder
int nonImgFiles = 3; //other files in sketch folder that are not images

String path;

void setup(){
  path = sketchPath();
}

void draw(){
 checkSize(); 
}

void checkSize() {
  File file = new File(path);
  if (file.isDirectory()) {
    String names[] = file.list();
    if (indexCap != (names.length - nonImgFiles)) {
      //update indexCap to number of images in folder
    } else {
     //indexCap hasn't changed, do nothing
    }
 }
}
1 Like