0

From my eclipse plugin i ask the user to enter a pattern, based on that i show the list of files that match the pattern. Ex user can enter some thing like this: *DAO or DAO etc.

How should i validated this pattern and match the file names in my code.

Krishnaveni
  • 799
  • 2
  • 11
  • 32
  • what do you need exactly? I do not understand your example. what have you tried? – vefthym Jul 22 '15 at 09:36
  • 1
    The answer to your question depends on the requirements, which you did not provide. – Manu Jul 22 '15 at 09:42
  • there is a dialog box, where user can select a folder and enter a pattern. I need to list out all the files from that folder that match the pattern. For ex: if user wants the list of files whose name ends with DAO, they will give *DAO in the pattern text box. – Krishnaveni Jul 22 '15 at 10:12

2 Answers2

0

I think what you want to do is globbing. According to this other answer, you could try FileSystem.getPathMatcher.

Community
  • 1
  • 1
Cos64
  • 1,617
  • 2
  • 19
  • 30
0

You can use Java FilenameFilter to filter files in a directory by any criteria you'd like:

File dir = new File(dirName);
FilenameFilter filenameFilter = new <your filter implementation>
File[] files = dir.listFiles(filenameFilter);

Apache Commons IO library has several useful implementation for this (by name, by pattern, by wildcard...).

Arye Shemesh
  • 582
  • 7
  • 20