var lastIndex = filename.lastIndexOf("\\");
if (lastIndex >= 0) {
filename = filename.substring(lastIndex + 1);
}
What this does is to find the last backslash. If one exists (if (lastIndex >= 0)
), then we remove everything leading up to it using substring
. In other words, the code removes the path before a file name.
Edit: I'm an idiot and messed up the substring
syntax. Corrected.