What happens if this has an http:// URL?  Can you keep the logic round the other way, and move the dir.relativeFilePath(...) bit into this if block?