modified function creating a directory to check, if the directory already exists