fixed an infiinte loop when creating directories.