Reputation: 6211
My script works to save the files to the same directory as the code. I want to save it somewhere else. I've verified the directory exists. I know this has been asked many times, but I feel like I'm doing what others have said and I'm still getting IOError: [Errno 2] No such file or directory:
filepath = os.path.join('/Dropbox/music_files', new_filename)
f = open(filepath, 'w+')
f.write(content)
f.close()
Upvotes: 0
Views: 114
Reputation: 19328
/Dropbox/music_files
existsIf not, use os.makedirs('/Dropbox/music_files')
to create the dir you want to save into
Also, context manager is always better.
import os
if not os.path.exists('/Dropbox/music_files'):
os.makedirs('/Dropbox/music_files')
filepath = os.path.join('/Dropbox/music_files', new_filename)
with open(filepath, 'w+') as f:
f.write(content)
Upvotes: 1