The fact that the last slash is included in the file name is not a problem. Only absolute path names (i.e., dir + file) are used as file URLs. The variable dir is just used as a key for looking up sets of files in the directory, so it doesn't matter whether the last slash is included in dir or file, or in neither.