Hello,
I had this code working at some point. However I’m not sure what I’ve changed and now it’s broken.
The method should open every file in a folder and in each subfolders (recursively) to check which one has less lines.
Assuming all files/folders are inside data folder, I can access individually each file as
// working
String[] s = loadStrings("/subfolder/test.csv");
println(s.length);
but the following does not work (anymore).
the structure I have is
/data
/subfolder
/test.csv
/subfolder2
/test2.csv
File folder;
void setup() {
folder = new File(dataPath(""));
println(folder); //prints correctly
int lineCount = 100000;
lineCount = lineCounter(folder, lineCount);
}
int lineCounter(File folder, int lineCount) {
for (File fileEntry : folder.listFiles()) {
if (fileEntry.isDirectory()) {
lineCounter(fileEntry, lineCount);
} else {
System.out.println(fileEntry.getName());
String[] lines = loadStrings(fileEntry.getName()); // prints filename correctly
if(lines.length < lineCount) // FAILS with The file "test.csv" is missing or inaccessible....
lineCount = lines.length;
}
}
return lineCount;
}