Is there any way to remove files on Google Drive using Google Colab?
I accidentally extracted files from zip on main Google Drive folder using Google Colab but cannot find a way to remove or move them
I encountered the same issue. I extracted(by mistake) my Dataset(more than 6000 images) to the google drive main folder, which led to many issues such as, every time mounting drive will take longer than usual, sometimes it gives drive-timeout error as it can not list all the files(https://research.google.com/colaboratory/faq.html#drive-timeout). To remove all files, I tried with "os.listdir" but it did not work(no idea why it doesn't). Here is the solution which worked for me:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With