Is there a reason why you are using `stat` here instead of `os.path.isdir(path)` and `os.path.isfile(path)` later? the `os.path` helpers are usually more readable.