• Post Reply Bookmark Topic Watch Topic
  • New Topic

Scanning directories in java  RSS feed

 
Shane Burgel
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way that I can scan a directory and return a list of files in java? Or to look for specific files or files that meet certain naming conventions etc?

Thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several methods in java.io.File that list the entries in a directory in different forms: two named list(), and three named listFiles(). Several of these methods take a FilenameFilter object as a parameter, and you can use these methods to -- you guessed it -- filter the list of names however you'd like by implementing a FilenameFilter.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!