• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

reply
    Bookmark Topic Watch Topic
  • New Topic