How to Extract Rar Files Inside Google Colab

How to extract all .rar files inside a folder (gdrive) from google colab?

For using variable in !unrar, you need to use this code

file_path = '/content/drive/MyDrive/Colab Notebooks/123.rar'
!unrar x '$file_path'

So, in your situation you will have next code:

data_path = "/content/gdrive/My Drive/folder"
for file in os.scandir(data_path):
!unrar x '$file.path' "/content/drive/path/output_folder/"

How To Extract Password Protected Rar File Using Patool On Google Colab

For 7z, you can use

! 7z e -pPASSWORD "path/to/file.zip"

to extract a file with password.

Unzip failed to finish in Google Colab

As @BobSmith said, I move all of my dataset to the google colab's local disk first and extract all of it using :

!unzip -u -q /content/syn_train_3.zip

and for rar using unrar

!unrar e real_train_500_2.rar train_dir

the extraction is proved faster. and I split the dataset to .npy files and save it to the drive again.

I found that Google Colab uses Google Drive File Stream like Backup and Sync in your desktop. It would be painful to wait the dataset synced between Colab and Drive.

Careful, don't let the "/drive/My Drive" in Google Colab fools you that it already saved to Google Drive, it needs time to sync!.



Related Topics



Leave a reply



Submit