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.
Page Index Toggle Pages: 1
wildcard? (Read 825 times)
wildcard?
Apr 23rd, 2008, 8:59pm
 
Hello,
I'm wondering if there's a way to use wildcards in Processing.
e.g.
I often use Supercollider to work with audio.
In SC I can type

array=(/folder/*.jpg).pathMatch;

and have that return an array of all of the filenames in '/folder/'
that end in .jpg.

Is something similar possible in Processing?

thanks.
Re: wildcard?
Reply #1 - Apr 24th, 2008, 1:02am
 
i had similar question not sure if this helps cause i was inquiring about sequential file loading check this post:

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1208988489
Re: wildcard?
Reply #2 - Apr 24th, 2008, 10:36am
 
i don't know any processing extended functions for this, but you can acomplish this with the java api by using the File object, basically you create a File object with the desired folder as a parameter and then list the contents of the folder by using the list() method. In your case you don't want all the files in the folder, so you should use the list() method that accepts a Filter for the type of files listed (I have never used it, so i can't help here) or you can  list all the files and then filter the ones you want.

Reference: http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html#list()
Example: http://www.java-tips.org/java-se-tips/java.io/list-the-names-of-all-files-in-a-particular-dire.html
Re: wildcard?
Reply #3 - Apr 24th, 2008, 3:57pm
 
Quote:


File dataFolder = new File(sketchPath, "data");
String[] names = dataFolder.list();
int foundCount = 0;
if (names != null) {
 for (int i = 0; i < names.length; i++) {
   // Skip hidden files and folders starting with a period
   if (names[i].charAt(0) != '.') continue;

   // Print files ending in .jpg or .JPG
   if (names[i].toLowerCase().endsWith(".jpg")) {
     println("Found JPEG image: " + names[i]);
     foundCount++;
   }
 }
 println("Found " + foundCount + " image(s).");
} else {
 println("Could not access images.");
}

Re: wildcard?
Reply #4 - Apr 24th, 2008, 8:58pm
 
thanks to you all for the input and especially to fry for taking the time to code that up, while showing some nice syntax to absorb.  looking forward to learning more of this language.

BUT

I'm getting this mesage:

Found 0 Images

and trying to troubleshoot....

should I be supplying a path at sketchPath in File(sketchPath, "data")?
or?

thanks again....

Re: wildcard?
Reply #5 - Feb 22nd, 2009, 12:09am
 
well two things to say to that
first you need to put your files in an data folder in the Sketch folder (Ctrl+k) opens the Sketch folder crate there a data folder and put some files in.

second there is an bug in the script
in the line (if you run a Windows)

   if (names[i].charAt(0) != '.') continue;

should read

   if (names[i].charAt(0) == '.') continue;

becaus then "continue;" breakes out of the loop if the filename starts whith '.' (hidden files on MAC)
before it always broke out of the loop especialy on a PC ;)
Page Index Toggle Pages: 1