【发布时间】:2021-05-06 18:48:39
【问题描述】:
我正在尝试从 Google 驱动器文件夹中删除所有扩展名为“.pdf”的文件。 API身份验证一切正常,我可以上传文件。问题在于删除。
我在这里上传
upload_file = 'Test1.pdf'
gfile = drive.CreateFile({'parents': [{'id': '11SsSKYEATgn_VWzSb-8RjRL-VoIxvamC'}]})
gfile.SetContentFile(upload_file)
gfile.Upload()
这里我尝试删除
delfile = drive.CreateFile({'parents': [{'id': '11SsSKYEATgn_VWzSb-8RjRL-VoIxvamC'}]})
filedel = "*.pdf"
delfile.SetContentFile(filedel)
delfile.Delete()
错误:
Traceback (most recent call last):
File "C:/Users/linol/Documents/ProjetoRPA-Python/RPA-TESTE.py", line 40, in <module>
delfile.SetContentFile(filedel)
File "C:\Users\linol\Documents\ProjetoRPA-Python\venv\lib\site-packages\pydrive\files.py", line 175, in SetContentFile
self.content = open(filename, 'rb')
OSError: [Errno 22] Invalid argument: '*.pdf'
【问题讨论】:
-
为什么不启动google colab,连接到驱动器并运行
!find '/content/drive/MyDrive' -type f -name '*.pdf' -delete? -
以上代码只是近 100 行代码的一部分。我正在使用 PyCharm
标签: python google-drive-api pydrive