private Path relPathToRoot ( Path fullPath , Path root ) { // just take some effort to do it // rather than just using substring // so that we do not break sometime later Path justRoot = new Path ( Path . SEPARATOR ) ; if ( fullPath . depth ( ) == root . depth ( ) ) { return justRoot ; } else if ( fullPath . depth ( ) > root . depth ( ) ) { Path retPath = new Path ( fullPath . getName ( ) ) ; Path parent = fullPath . getParent ( ) ; for ( int i = 0 ; i < ( fullPath . depth ( ) - root . depth ( ) - 1 ) ; i ++ ) { retPath = new Path ( parent . getName ( ) , retPath ) ; parent = parent . getParent ( ) ; } return new Path ( justRoot , retPath ) ; } return null ; }
truncate the prefix root from the full path