Fix for issue when file or directory name is "0"

Backport of #4266 for LTS