Python [Errno 17] File exists Issue -
in python, when folder created first time, directory created , files created in folder path. when again new file needs created in same location, i'm getting error:
[errno 17] file exists: '/home/test/files/tweets/'.
any suggestions please?
if len(downloadedfile) > 0: #insert_time=time.strftime('%y_%-m_%-d') #download_path='/home/test/files/tweets/' #file_path= download_path+insert_time+"/"+hashes #print(file_path) = datetime.now new_folder = '/home/test/files/tweets/{}'.format(now().strftime('%y_%-m_%-d')) os.mkdir(new_folder, 0755 ); folder_path = new_folder+"/"+hashes fo = open(folder_path,"wb") fo.write(downloadedfile) fo.close() print("file downloaded") else: print("file not downloaded")
catch oserror
try:except:
:
try: os.mkdir(new_folder, 0755) except oserror: pass
this bit unsatisfactory, there other errors might ignore.
Comments
Post a Comment