Ras*_*dha 3 python google-colaboratory
有没有办法使用 Google Colab 删除 Google Drive 上的文件?
我不小心使用 Google Colab 从 Google Drive 主文件夹上的 zip 中提取了文件,但找不到删除或移动它们的方法
小智 6
我遇到了同样的问题。我(错误地)将我的数据集(超过 6000 个图像)提取到 google 驱动器主文件夹,这导致了许多问题,例如,每次安装驱动器将花费比平常更长的时间,有时它会给出驱动器超时错误,因为它不能列出所有文件(https://research.google.com/colaboratory/faq.html#drive-timeout)。要删除所有文件,我尝试使用“os.listdir”,但它不起作用(不知道为什么它不起作用)。这是对我有用的解决方案:
import os
import glob
# my all files starts with "frame" and ends with ".jpg"
fileList = glob.glob('/content/drive/MyDrive/frame*.jpg')
print("Number of files: ",len(fileList))
for filePath in fileList:
try:
os.remove(filePath)
except:
print("Error while deleting file : ", filePath)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11581 次 |
| 最近记录: |