public static void deleteEmptyParentDirectories ( FileSystem fs , Path limitPath , Path startPath ) throws IOException { if ( PathUtils . isAncestor ( limitPath , startPath ) && ! PathUtils . getPathWithoutSchemeAndAuthority ( limitPath ) . equals ( PathUtils . getPathWithoutSchemeAndAuthority ( startPath ) ) && fs . listStatus ( startPath ) . length == 0 ) { if ( ! fs . delete ( startPath , false ) ) { log . warn ( "Failed to delete empty directory " + startPath ) ; } else { log . info ( "Deleted empty directory " + startPath ) ; } deleteEmptyParentDirectories ( fs , limitPath , startPath . getParent ( ) ) ; } }
Deletes empty directories starting with startPath and all ancestors up to but not including limitPath .