public static String locateDirectory ( String dirName ) throws IOException { if ( Utils . dirExists ( dirName ) ) return dirName ; String path = null ; String curDir = new File ( "." ) . getCanonicalPath ( ) ; // Go for at most 10 levels up for ( int i = 0 ; i < 10 ; i ++ ) { path = String . format ( "%s/%s" , curDir , dirName ) ; if ( Utils . dirExists ( path ) ) break ; curDir = String . format ( "%s/.." , curDir ) ; } if ( path != null ) { File file = new File ( path ) ; path = file . getCanonicalPath ( ) ; if ( ! Utils . dirExists ( path ) ) path = null ; } return path ; }
Locates the given dirName as a full path in the current directory or in successively higher parent directory above .