public static Map < String , List < String > > findImages ( File rootDir ) { File files [ ] = rootDir . listFiles ( ) ; if ( files == null ) return null ; List < File > imageDirectories = new ArrayList <> ( ) ; for ( File f : files ) { if ( f . isDirectory ( ) ) { imageDirectories . add ( f ) ; } } Map < String , List < String > > out = new HashMap <> ( ) ; for ( File d : imageDirectories ) { List < String > images = new ArrayList <> ( ) ; files = d . listFiles ( ) ; if ( files == null ) throw new RuntimeException ( "Should be a directory!" ) ; for ( File f : files ) { if ( f . isHidden ( ) || f . isDirectory ( ) || f . getName ( ) . endsWith ( ".txt" ) ) { continue ; } images . add ( f . getPath ( ) ) ; } String key = d . getName ( ) . toLowerCase ( ) ; out . put ( key , images ) ; } return out ; }
Loads the paths to image files contained in subdirectories of the root directory . Each sub directory is assumed to be a different category of images .