Protect script against "Permission denied" error and directories with spaces