4

I am trying to unzip a folder by passing it a variable in Google-colab. However when I do it, it doesn't show up in my folders.

If I do it by passing it directly the name, like in this answer here: Extract Google Drive zip from Google colab notebook

!unzip TASI.zip

I get this output:

rchive:  TASI.zip
  inflating: TASI/Output [11-13(1) _good_; 18_06_2019 15_58_09].csv  
  inflating: TASI/Output [11-15(1) _good_; 18_06_2019 15_51_26].csv  
  inflating: TASI/Output [11-46(1) _good_; 18_06_2019 15_41_08].csv  
  inflating: TASI/Output [11-47(1) _good_; 18_06_2019 15_36_31].csv  
  inflating: TASI/Output [3-14(1) _good_; 18_06_2019 14_06_52].csv  
  inflating: TASI/Output [3-18(1) _good_; 18_06_2019 13_55_35].csv  
  inflating: TASI/Output [4-31(1) _bad_; 18_06_2019 14_51_19].csv  

And the folder appears in my colab files.

If I do it by passing it the variable:

file_folder="TASI.zip"
!unzip -c "$file_folder" 

In the output it shows me the content of every file. And the folder does not appear in the colab files. Output:

Archive:  TASI.zip
  inflating: TASI/Output [11-13(1) _good_; 18_06_2019 15_58_09].csv  

SetupTitle, Output
PrimitiveTest, I/V Sweep
TestParameter, Context.MainFrame, 4155C
TestParameter, Channel.UnitType, SMU, SMU, SMU
TestParameter, Channel.Unit, SMU3:MP, SMU4:MP, SMU1:MP
TestParameter, Channel.IName, ID, IS, IG
TestParameter, Channel.VName, VD, VS, VG
TestParameter, Channel.Mode, V, COMMON, V
TestParameter, Channel.Func, VAR1, CONST, VAR2....

How do I unzip the folder in colab passing it a variable?

Leo
  • 1,176
  • 1
  • 13
  • 33
  • 2
    you are not running exactly the same command so why you expect them to work the same? have you checked what the "-c" flag does? from my understanding it tells unzip to unzip the files to STDOUT/screen rather than to a folder – Chris Doyle Jun 19 '19 at 13:27
  • Taking the "-c" out fixed it. I had taken the code online from someone trying to pass a variable, I guess they were using it In a different way than I am. thank! – Leo Jun 19 '19 at 13:37

1 Answers1

4

The -c flag to unzip is defined as extract files to stdout/screen (''CRT''). the two commands you are running are not the same, in the command where you specifically provide the file name you dont use the -c option so unzip extracts to the filesystem. In the command where you give a variable you use the -c flag telling unzip just to extract the files to the screen.

Try unzip with the variable but without the -c flag.

file_folder="TASI.zip"
!unzip "$file_folder" 
Chris Doyle
  • 10,703
  • 2
  • 23
  • 42