Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compress files in google drive?

Is there any way to compress large files into smaller .zip of .tar.gz files in google drive? I tried google appscript but it created .zip files but not compressing. How to do this?

like image 851
prashanth-g Avatar asked Dec 01 '22 18:12

prashanth-g


2 Answers

I found there is an efficient, fast, simple but indirect method of zipping/unzipping the large files into Google Drive using Google Colaboratory.

For example, Let us assume there is a directory named Dataset of size 5 GB in your Google Drive, the task is to zip (compress) it to Dataset.zip.

Google Drive:

My Drive

Dataset

Steps:

  1. Open Google Colab (it's free), Create a New Notebook.
  2. Mount Google drive into Google Colab by running the following command lines:

    from google.colab import drive drive.mount('/content/gdrive')

    Note: Now on the left side (Files) you can observe your My Drive inside gdrive and folder Dataset inside My Drive.

Screenshot before zipping.

Colab Drive Mount

  1. Change the current directory by following command run.

    cd gdrive/My Drive/

  2. Zip files/folder: Dataset to Dataset.zip using the following command run.

    !zip -r Dataset.zip Dataset/

Screenshots after zipping:

Colab Drive Mount after zipping

Google Drive Screenshot after zipping

Note: The above commands are inspired by ubuntu. Hence, for unzipping use:

!unzip filename.zip -d ./filename

like image 106
Bharat Giddwani Avatar answered Dec 04 '22 07:12

Bharat Giddwani


I have tried and tested the below code with a pdf file which is in my Drive of 10MB size and it did compressed it for 9MB. I even tested for a Drive file(slides), it did compress it.

function fileZip(){
 var files = DriveApp.getFilesByName('Google_Apps_Script_Second_Edition.pdf');
  while (files.hasNext()) {
    var file = files.next();
 file = file.getBlob()}

DriveApp.createFile(Utilities.zip([file], 'tutorialFiles.zip'));

}

Hope that helps!

like image 33
KRR Avatar answered Dec 04 '22 07:12

KRR