Fix issues #3005 and #3009.
make the chdir error message more helpful by also printing the folder name