• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scan files which having wild cards using apache DirectoryScanner

 
Harshana Dias
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Im using apache directory scanner to scan files in a path having wildcards.


The problem here is if i use the above code it will only display java files inside sub directories of Temp and not java files which are directly in Temp folder.

Also I have notice if i use (new String[]{"*.java"}) then it will list all the java files in Temp folder and (new String[]{"**/*.java"}) will list all the java files even inside sub directories of sub directory. So my questions here are,

1) Is this the standard wild card syntax that apply for every where? i mean **/ means all directories and */ means only sub directories?

2)How to get files which are in Temp directory directly and inside sub directoroes only (not again inside those sub directories like we use **)

3)Now we can see when using DirectoryScanner we have base directory and then the relavanat wildcard syntax. But suppose we have wildcards in middle of the base directoy too. If so how can we use the DirectoryScanner?

Thank You.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not really familiar with Apache Directory Scanner, but here are my answers.

Harshana Dias wrote:1) Is this the standard wild card syntax that apply for every where? i mean **/ means all directories and */ means only sub directories?

It certainly isn't standard for everything. But it seems to be reasonably common for modern open-source software, when talking about files.

Harshana Dias wrote:2)How to get files which are in Temp directory directly and inside sub directoroes only (not again inside those sub directories like we use **)

I would try

The reason they use an array there is that they want to allow multiple entries (and they're still in the pre-JDK 5 dark ages). I would assume that if you put multiple entries into the array, they will be used.

Harshana Dias wrote:3)Now we can see when using DirectoryScanner we have base directory and then the relavanat wildcard syntax. But suppose we have wildcards in middle of the base directoy too. If so how can we use the DirectoryScanner?

I would use the DirectoryScanner twice, or more. The first time, set the base directory to something like "C:/", and search for directories that match the pattern with a wildcard. Then use DirectoryScanner once more for each matching directory you found, setting that directory as base directory.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic