If you are going to extract this into a method, give these variables slightly more descriptive names (e.g. "dir" and "ext"). Also use interpolation rather than multiple concatenations