code: protected File getRelativeFile( File baseDir, File targetFile ) throws IOException
      {
          String baseDirStr = baseDir.getPath();
          String targetDirStr = targetFile.getPath();
          
          if ( targetDirStr.equals( baseDirStr ) )
          {
              return new File( "." );
          }
          else if ( targetDirStr.startsWith( baseDirStr + File.separator ) ) // add slash to ensure directory
          {
              return new File( targetDirStr.substring( baseDirStr.length() + 1 ) ); // + slash char
          }
          
          throw new IOException( "Unable to relativize " + targetDirStr + " to " + baseDir );
      }
docs: Compute the relative path portion from a path and a base directory.
  If basedir and target are the same "." is returned.
  For example: Given C:\foo\bar and C:\foo\bar\baz this method will return baz
  @param baseDir the base directory
  @param targetFile the path to express as relative to basedir
  @return the relative portion of the path between basedir and target
  @throws IOException if the target is not basedir or a subpath of basedir