use ```os.path.dirname``` to check if the dir exists and to set permissions to ```700```.