有没有办法使用Google Colab删除Google Drive上的文件?
我不小心用Google Colab解压了Google Drive主文件夹上的zip文件,但找不到移除或移动它们的方法
发布于 2021-02-18 10:45:04
我遇到了同样的问题。我提取(错误地)我的数据集(超过6000张图片)到谷歌驱动器主文件夹,这导致了许多问题,例如,每次安装驱动器将花费比平时更长的时间,有时它会给驱动器超时错误,因为它不能列出所有的文件(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)
https://stackoverflow.com/questions/62496307
复制相似问题