Might be worth considering some preliminary checks on the filename so if doesn't have the expected structure/length the user gets an informative error rather than these being empty strings and the code failing silently.