Created
December 11, 2021 14:53
-
-
Save meet-minimalist/0d4809358168329a688b10df2c29650a to your computer and use it in GitHub Desktop.
Download upload files to google drive using PyDrive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tqdm import tqdm | |
from pydrive.auth import GoogleAuth | |
from pydrive.drive import GoogleDrive | |
gauth = GoogleAuth() | |
drive = GoogleDrive(gauth) | |
# View all folders and file in your Google Drive | |
# fileList = drive.ListFile({'q': "'root' in parents"}).GetList() | |
with open('file_names.txt', 'r') as f: | |
lines = f.readlines() | |
for line in tqdm(lines[746:]): | |
file_name = line.replace('\n', '') | |
fileList = drive.ListFile({'q': f"title contains '{file_name}'"}).GetList() | |
for file in fileList: | |
# To download file | |
# file.GetContentFile(f"./photos/{file['title']}") | |
# print('Title: %s, ID: %s, downloaded.' % (file['title'], file['id'])) | |
# To delete file and move it to trash | |
file.Trash() | |
print('Title: %s, ID: %s, deleted.' % (file['title'], file['id'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment