I have a folder consist of many .rar
files. I need to extract all .rar
files inside that folder. I’ve mounted my gdrive account to the colab. What I’ve done is:
JavaScript
x
4
1
data_path = "content/gdrive/My Drive/folder"
2
for file in os.scandir(data_path):
3
!unrar x file.path "/content/drive/path/output_folder/"
4
but I got error:
JavaScript
1
4
1
Cannot open file.path
2
No such file or directory
3
No files to extract
4
I think file.path
will work since when I used:
JavaScript
1
3
1
for file in os.scandir(data_path):
2
print(file.path)
3
It prints all file paths in that folder
How to accomplish it efficiently?
Advertisement
Answer
For using variable in !unrar, you need to use this code
JavaScript
1
3
1
file_path = '/content/drive/MyDrive/Colab Notebooks/123.rar'
2
!unrar x '$file_path'
3
So, in your situation you will have next code:
JavaScript
1
4
1
data_path = "/content/gdrive/My Drive/folder"
2
for file in os.scandir(data_path):
3
!unrar x '$file.path' "/content/drive/path/output_folder/"
4