{ Burak Dede | Online Writings }
Sign in to compose/edit

Deeply Search Files In Given Directory Java - Recursive Way

For one of my Java projects I need to search files and directories within given directory, so i need to come up with optimal solution cause when i searched a little for this problem the codes floating around are just useless some of them not searching in a deep way or some of them are written in a poor way. So I come up with my own solution that do the job with recursive way. Here is a code for that.

public void deepRecSearch( File givenDir ) throws IOException {
    if (givenDir.isDirectory()) {
        final File[] childs = givenDir.listFiles();
        for( File child : childs ) {
           deepRecSearch(child);
        }    
        return;
    }
//put your implementation about file here
//like what you wanna do with that file print absolutePath or sth
}
 
blog comments powered by Disqus

Burak Dede

I am computer engineer and programmer living in Istanbul, Turkey. This site contains my online writings mostly about software development and programming languages.

RSS Feed

Subscribe to feed

Subscribe to get latest posts from this blog if you are regular reader.

Burak Dede © 2011
About @Contact RSS