Java tutorial
//package com.java2s; import java.io.File; import java.util.TreeMap; public class Main { private static TreeMap<String, String> pathMap; public static void U7remove(String nm) { String fname = U7exists(nm); if (fname != null) { File f = new File(fname); f.delete(); } } public static final String U7exists(String nm) { String name = getSystemPath(nm); int uppercasecount = 0; do { if (new File(name).exists()) return name; // found it! } while ((name = baseToUppercase(name, ++uppercasecount)) != null); return null; } public static String getSystemPath(String path) { String newPath; int pos, pos2; pos = path.indexOf('>'); pos2 = path.indexOf('<'); // If there is no separator, return the path as is if (pos == -1 || pos2 != 0) { newPath = path; } else { pos += 1; // See if we can translate this prefix String syspath = path.substring(0, pos); if (isSystemPathDefined(syspath)) { String newPrefix = pathMap.get(syspath); newPath = newPrefix + path.substring(pos); } else { newPath = path; } } return newPath; } private static String baseToUppercase(String str, int count) { if (count <= 0) return str; int todo = count, i; // Go backwards. for (i = str.length() - 1; i >= 0; --i) { int c = str.charAt(i); if (c == '/') { todo--; if (todo <= 0) break; } } if (todo > 0) return null; // Didn't reach 'count' parts. String res = str.substring(0, i) + str.substring(i, str.length()).toUpperCase(); return res; } public static boolean isSystemPathDefined(String path) { return pathMap != null && pathMap.containsKey(path); } }