fix #1293, check if directory name is a positive integer before casting it

Fix issue #1293