Replace '/'.join(f.split('/')[:-1]) with the equivalent posixpath.dirname(f)

(which will work correctly regardless of host platform)

This makes the code easier to follow, since that join/split isn't necessarily obvious tree-walking at first glance.