Loading...
Logo
Processing Forum

Get all the files from a folder?

in General Discussion  •  Other  •  28 days ago  
I have several .SVG's I'm loading from a folder, and I'm wondering if there's a way to load everything from a folder regardless of how many objects are in there. I saw the selectFolder() function but I'd like to do it automatically for one specific folder, without a prompt

Replies(5)

I'm not gonna lie I have zero idea what is happening in that thread. I don't need the files to have been modified and the addition of that functionality is confusing the hell out of me. I don't expect the work to be done for me but maybe somebody could tell me which functions I should be looking at specifically? I'm gonna dig into a Java book right now and hopefully come up with some answers
Indeed, about 85% or more of that program can be thrown away for your specific purpose.
But it was what I had as example!    I also had to learn a lot to help coding that too.

Basically what you need is:
final static File[] getFolderContent(File dir) {
  return dir.listFiles(pictsFilter);
}

And the FilenameFilter object being used there as extension choice filter.
Just replace variable exts content to use ".svg" instead:
final static String[] exts = {
  ".gif", ".png", ".jpeg", ".jpg"
};

final static FilenameFilter pictsFilter = new FilenameFilter() {
  boolean accept(File dir, String name) {
    name = name.toLowerCase();
    for (int i = exts.length; i-- != 0;)  if (name.endsWith(exts[i]))  return true;
    return false;
  }
};

Problem is, function getFolderContent(), which in turn merely calls listFiles() method, demands a File object.
However, that program doesn't explicit instantiates a File object!
Rather, it uses 1 created by selectFolder()'s thread.

Perhaps you should take a look @ http://docs.oracle.com/javase/6/docs/api/java/io/File.html yourself.
I still got a lot to learn from that File class yet. 

If you still got any problems, publish your current code here so we can try to reach your goal. 
Awesome, thanks guys. Just getting into Java proper as of recently, I knew there had to be a way!