/** * Get the relative path between two virtual files * * @param parent the parent * @param child the child * @return the relative path */ static String getRelativePath(VirtualFile parent, VirtualFile child) { if (child == null) { throw new IllegalArgumentException("Null child"); } String childPath = child.getPathName(); if (parent != null) { String parentPath = parent.getPathName(); if (parentPath.length() == childPath.length()) { return ""; } // Not sure about this? It is obviously not a direct child if it is shorter? if (parentPath.length() < childPath.length()) { if (!parentPath.endsWith("/")) { parentPath = parentPath + "/"; } if (childPath.startsWith(parentPath)) { return childPath.substring(parentPath.length()); } } } if (childPath.endsWith("/")) { childPath = childPath.substring(0, childPath.length() - 1); } return childPath; }