public static String getRelativeFilename ( String sourcePath , String baseDir ) { if ( sourcePath . contains ( baseDir ) ) { int indexOf = sourcePath . indexOf ( baseDir ) ; if ( indexOf + baseDir . length ( ) < sourcePath . length ( ) ) { String relative = sourcePath . substring ( ( indexOf + baseDir . length ( ) ) ) ; if ( relative . startsWith ( "/" ) ) { relative = relative . substring ( 1 ) ; } else if ( relative . startsWith ( "\\" ) ) { relative = relative . substring ( 1 ) ; } return relative ; } } return sourcePath ; }
Removes the base directory from a file path . Leading slashes are also removed from the resulting file path .