~mike32767/qtunes/trunk

« back to all changes in this revision

Viewing changes to src/org/qtunes/core/util/FileUtils.java

  • Committer: mike at qtunes
  • Date: 2014-11-17 11:51:36 UTC
  • mfrom: (152.1.8 qtunes)
  • Revision ID: mike@qtunes.org-20141117115136-pbu3y9afonqw1l09
Merged from launchpad

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
     * relative path from root to file
53
53
     */
54
54
    public static File getRelativeFile(File file) throws IOException {
55
 
        List<String> rootbits = new ArrayList<String>(Arrays.asList(root.get().getCanonicalPath().split(File.separator)));
56
 
        List<String> filebits = new ArrayList<String>(Arrays.asList(file.getCanonicalPath().split(File.separator)));
 
55
        List<String> rootbits = new ArrayList<String>(Arrays.asList(split(root.get().getCanonicalPath(), File.separatorChar)));
 
56
        List<String> filebits = new ArrayList<String>(Arrays.asList(split(file.getCanonicalPath(), File.separatorChar)));
57
57
        int i = 0;
58
58
        while(i < rootbits.size() && i < filebits.size() && rootbits.get(i).equals(filebits.get(i))) {
59
59
            i++;
89
89
        return p1.equals(p2);
90
90
    }
91
91
 
 
92
    /**
 
93
     * Like String.split but not regex sensitive, for splitting D:\\path\\
 
94
     * type input
 
95
     */
 
96
    private static String[] split(String in, char sep) {
 
97
        int count = 1;
 
98
        for (int i=0;i<in.length();i++) {
 
99
            if (in.charAt(i) == sep) {
 
100
                count++;
 
101
            }
 
102
        }
 
103
        String[] out = new String[count];
 
104
        count = 0;
 
105
        int j = 0;
 
106
        for (int i=0;i<in.length();i++) {
 
107
            if (in.charAt(i) == sep) {
 
108
                out[j++] = in.substring(count, i);
 
109
                count = i+1;
 
110
            }
 
111
        }
 
112
        out[j] = in.substring(count);
 
113
        return out;
 
114
    }
 
115
 
92
116
}