I wrote a script that uploads files to google drive, now I want to add the upload to a specific folder, but it doesn’t work


This Content is from Stack Overflow. Question asked by Ramz

def upload_dir(dir_path='', real_folder_id=''):

    drive = GoogleDrive(gauth)
    folder_id = real_folder_id
    for file_name in os.listdir(dir_path):
        my_file = drive.CreateFile({'title': f'{file_name}', 'parents': [folder_id]})
        my_file.SetContentFile(os.path.join(dir_path, file_name))
        print(f'File {file_name} was uploaded!')
    return 'Success!Have a good day!'
except Exception as _ex:
    return 'Got some trouble, check your code please!'

def main():
print(upload_dir(dir_path=IMAGES_FOLDER, real_folder_id=’15dMpzAou2teJ2qmq-76ZHr4t9ujNIa9_’))


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?