• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is it possible to write a reg exp to search for files?  RSS feed

 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using Java 1.5. In a certain directory, I want to search for the presence of a file, say "a.txt" and if that exists, then create a file "a-1.txt". If there is an "a.txt" and an "a-1.txt" file, I want to create a "a-2.txt" file. Short of doing loops, is there a way I can check if a "a-#.txt" file exists, and what that # is using regular expressions somehow?

Thanks, - Dave
 
Travis Hein
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sure you can, there is the java.io.FileFilter interface, provide your own implementation, which requires you create an accept() method, that returns true if the file found is one you want to include in the filtered find file results, or to make it return false if you do not want to see the file.

such as



and then invoke this as

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!