class ThemeBuilderUtils {

    public static String calculatePathToFile(File fromFile, File toFile) {
        String pathToFile = "";

        int directoriesUp = 0;
        String parentPath = fromFile.getParent();

        while ((parentPath != null) && !fileMatchesPath(parentPath, toFile)) {
            File parent = new File(parentPath);

            parentPath = parent.getParent();
            directoriesUp += 1;
        }

        if (parentPath != null) {
            for (int i = 0; i < directoriesUp; i++) {
                pathToFile += "../";
            }

            String remainingPath = toFile.getPath().replace(parentPath, "");

            if (remainingPath.startsWith(File.separator)) {
                remainingPath = remainingPath.substring(1);
            }

            // switch path separators
            remainingPath = remainingPath.replaceAll("\\\\", "/");

            // remove file name from path
            if (remainingPath.contains("/")) {
                int separatorIndex = remainingPath.lastIndexOf("/");
                remainingPath = remainingPath.substring(0, separatorIndex + 1);
            } else {
                // file in same directory, no remaining path
                remainingPath = null;
            }

            if (remainingPath != null) {
                pathToFile += remainingPath;
            }
        }

        return pathToFile;
    }

}