Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Wildcards....  RSS feed

 
David Leland
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm assuming this is the correct forum for this question. I searched several forums without any luck. I'm guessing its the term I'm using for the search.
In short, I'm trying to do a wildcard search of a directory. I want all files that begin with blue. In DOS, I'd do a dire blue*.*. In Java I'm unsure how to do it?
I could always use parse the file name. But it seemed like the Java language might have a class or an easier way to accomplish the same task.
Thanks in advance for any help.
D
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.io.File has several methods for listing files and directories under the directory represented by the File instance.
String[] list(FilenameFilter)
File[] listFiles(FilenameFilter)
File[] listFiles(FileFilter)
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a simple demo:

A more flexible approach might utilize the java.util.regex package in JDK 1.4:

Here you can replace the pattern with anything you want, provided you understand the syntax for regular expressions. Worth your time to learn this if it's not already familiar.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!