• Post Reply Bookmark Topic Watch Topic
  • New Topic

Recursive file search and still filtering file and directory names?

 
Jean Baro
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can any one help me with the code below?

The first problem with it, and the more important, is that if I don't check for directories in the filter, the code will not work, because the content (subdirectories and theirs content) won't be traversed, but if I do check I'll get directories from the search which were not supposed to be returned. I don't want to add another filter into the callbacks () as it will degrade the code's quality (not as it were brilliant code ).

The second problem is the line. I think as I start the search always with a DIRECTORY it won't get here if it's not a filtered file. I couldn't get proofs from a few tests I did, so it seems OK. What do you guys think?

The third problem is about performance, I know recursive code is not the best one out there regarding performance(although it is elegant and reasonably simple to understand). Is there any simple alternative with better performance?

Any other tip would be much appreciated.

Regards

 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jean Baro wrote:
The third problem is about performance, I know recursive code is not the best one out there regarding performance(although it is elegant and reasonably simple to understand). Is there any simple alternative with better performance?

Recursion is not a problem - File.listFiles() with callback filter is performing very poorly.
I tried to use this method to traverse a directory with about 250.000 - 500.000 files on a network drive and it took about 1-2 hours.
Finally I implemented this calling Windows "dir > file" command with output redirected to a file (dir with recursive option that lists the whole directory tree)
then in java program I read and parse this file using regex - it takes no more than 5 min.
In JDK 7 the performance of File.listFiles would be probably better ... we will see.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!