this line (together with the line above) doesn't consider the edge case where the file is in the root directory... but it might not be worth worrying about, IMHO