【发布时间】:2023-04-08 18:48:02
【问题描述】:
我正在开发一个 python 脚本,它将文件上传到我的驱动器中的特定文件夹,我注意到,驱动器 api 提供了一个很好的实现,但我确实遇到了一个问题,怎么做我一次删除多个文件?
我尝试从驱动器中获取我想要的文件并组织他们的 ID,但没有运气......(下面的 sn-p)
dir_id = "my folder Id"
file_id = "avoid deleting this file"
dFiles = []
query = ""
#will return a list of all the files in the folder
children = service.files().list(q="'"+dir_id+"' in parents").execute()
for i in children["items"]:
print "appending "+i["title"]
if i["id"] != file_id:
#two format options I tried..
dFiles.append(i["id"]) # will show as array of id's ["id1","id2"...]
query +=i["id"]+", " #will show in this format "id1, id2,..."
query = query[:-2] #to remove the finished ',' in the string
#tried both the query and str(dFiles) as arg but no luck...
service.files().delete(fileId=query).execute()
是否可以删除选定的文件(我不明白为什么不能,毕竟这是一个基本操作)?
提前致谢!
【问题讨论】:
标签: python google-api google-drive-api delete-file google-api-python-client