// Skip is counted by number of backslashes (\), not by segments.
private static String buildAddress(String rawPath, int skipBackslashes) {
if (rawPath == null || rawPath.isEmpty()) return "";
// Find index right after the N-th backslash
int seen = 0;
int start = 0;
for (int i = 0; i < rawPath.length(); i++) {
if (rawPath.charAt(i) == '\\') {
seen++;
if (seen == skipBackslashes) {
start = i + 1; // start AFTER N-th '\'
break;
}
}
}
// If we never reached N backslashes, nothing to show
if (skipBackslashes > 0 && seen < skipBackslashes) return "";
String tail = rawPath.substring(start);
// trim leading/trailing '\' around the tail
while (tail.startsWith("\\")) tail = tail.substring(1);
while (tail.endsWith("\\")) tail = tail.substring(0, tail.length() - 1);
// normalize separators to '/'
return tail.replace('\\', '/');
}