delete old files that have been replaced by a directory

Fixes #417.
Replaces #1086, more logical code.
test this fix with a cucumber feature
Merge pull request #1118 from maul-esel/dir-bug-take2

[bugfix #417] delete old files that have been replaced by a directory