1

I accidentally extracted a zip of a pet dataset into my google drive directory. Now I have like 30,000 cat and dog images in my directory that I can't get rid of. Due to the number of images in my directory, I can no longer connect to google drive through colab. Anyone have an idea to remove these images... Removing them by hand isn't an option given the webpage crashes when so many images a selected.

1
  • 2
    "the webpage crashes when so many images a selected". Remove them in batches. Commented Dec 20, 2019 at 21:22

3 Answers 3

0

EDIT

"finding the images isn't difficult, but selecting them all and deleting them is"

  • Create a new folder
  • Select as many as you can (in batches) using Cmd + Shift or Ctr + Shift and move them there (right click move to or "drag and drop").
  • Repeat as many times as needed
  • Delete the folder

Original answer

See different options using Advanced search.

You could try something like:

after:2019-12-19 before:2019-12-20 owner:me type:image

enter image description here

Read more about Advanced search

4
  • so all the images follow a certain formate e.g cat_1289.png. So finding the images isn't difficult, but selecting them all and deleting them is.
    – Javant
    Commented Dec 20, 2019 at 21:39
  • In that case as mentioned delete in batches. Select and move to a folder and delete the folder. Commented Dec 20, 2019 at 21:40
  • It would probably take you longer to write a script. :) Commented Dec 20, 2019 at 21:41
  • Please check the updated answer. Commented Dec 20, 2019 at 21:50
1

To delete a bulk of cat/dog png(image) files having a count of 30,000 from MyDrive in Google. I have two approaches here to perform the bulk delete action.

In the first approach, one can execute the following steps in Google Colaboratory.

Approach 1

Execute the following steps in Google Colaboratory:

  1.  Python Code to move all PNG files to the Trash folder in Google Drive
from google.colab import drive
drive.mount('/content/drive', force_remount=True, timeout_ms=900000)
cd /content/drive/MyDrive/
!rm *png
  1. Navigate to Trash folder in Google Drive and click the Delete Forever button.

Approach 2

In the second approach, one can execute the following Python code

import os
from google.colab import drive**
drive.mount('/content/drive', force_remount=True, timeout_ms=900000)
cd /content/drive/MyDrive/

#using listdir() method to list the files of the folder

test = os.listdir('/content/drive/MyDrive/')

# taking a loop to remove all the images
# using ".png" extension to remove only png images
# using os.remove() method to remove the files

for images in test:

    if images.endswith(".png"):

        os.remove(os.path.join(folder_path, images))
0

It looks that Google Drive on the web doesn't have anymore the select all command, so if you want to delete this files through the web UI, you should do it batches and it will take a while.

One alternative is to use a one of the apps for Windows and Mac (Google Drive Sync and Backup or File Stream for Google Drive)

Another alternative is to use Google Apps Script and/or the Google Drive API or a third party tool.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.