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?
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:
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
Change the current directory by following command run.
cd gdrive/My Drive/
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
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!
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