17

Mathematica can import zipped files automatically, but when the content of the zip file it's another zipped file, I just get the list of files in the second zip:

In[317]:= Import["http://www.meff.com/docs/Ficheros/Descarga/dRV/RV120312.zip","*"]
Out[317]={{TGENTRADES.M3,CCONTRGRP.C2,CCONTRTYP.C2,CCONTRACTS.C2,CCONTRSTAT.C2,CTHEORPRICES.C2,CDELTAS.C2,CINTRASPR.C2,CINTERSPR.C2,CVALARRAYS.C2,CYIELDCURVE.C2,CVOLATILITYSKEW.C2,MCONTRACTS.M3}}

How can I get the content of the last files ?

crazzymath
  • 451
  • 4
  • 12

1 Answers1

21

The documentation for the MIME type ZIP does not seem to say much about what you want to do, but luckily the first thing I tried worked!

First, I saved your zip file onto my desktop. Then, I extracted the first level of file names (note that "FileNames" is the default option, so is not explicitly needed)

In[1]:= fn1 = Import["/home/simon/Desktop/RV120312.zip", "FileNames"]
Out[1]= {"today_rv.zip"}

Then the second level of file names

In[2]:= fn2 = Import["/home/simon/Desktop/RV120312.zip", {fn1[[1]], "FileNames"}]
Out[2]= {"TGENTRADES.M3", "CCONTRGRP.C2", "CCONTRTYP.C2", \
    "CCONTRACTS.C2", "CCONTRSTAT.C2", "CTHEORPRICES.C2", "CDELTAS.C2", \
    "CINTRASPR.C2", "CINTERSPR.C2", "CVALARRAYS.C2", "CYIELDCURVE.C2", \
    "CVOLATILITYSKEW.C2", "MCONTRACTS.M3"}

Finally, I extracted, for example, the third file in the inner archive

In[4]:= Import["/home/simon/Desktop/RV120312.zip", {fn1[[1]], fn2[[3]]}]
Out[4]= {{"\"20120312\";\"C2\";\"20\";\"0100\";\"FuturoC IBEX MINI\";1;1", 
  "00;\"EUR\";\"1\";\"FFICSX\""}, {...}, ....}

I think that this final Import defaulted to a CSV import, when you seem to want to separate elements by semicolons (";"), so you should use:

In[5]:= Import["/home/simon/Desktop/RV120312.zip",{fn1[[1]], fn2[[3]], "Table"}, 
           "FieldSeparators"->";"] // Short[#,3]&
Out[5]//Short= {{20120312, C2, 20, 100, FuturoC IBEX MINI, 
                 1, 1,00, EUR, 1, FFICSX}, <<916>>, 
                {20120312, C2, VI, 240, Contado VIVENDI, 
                 1, 1,00, EUR, 2, ESXXXX}}

Note that you could, e.g., use a While loop to automate the digging down to the lowest level of the archive.

Simon
  • 10,167
  • 5
  • 57
  • 72
  • Just to complete the response. I'm importing only the 4th file, but I can't read dates properly:

    Import["http://www.meff.com/docs/Ficheros/Descarga/dRV/RV120314.zip", \ {"today_rv.zip", "CCONTRSTAT.C2", "Table"}, "FieldSeparators" -> ";", "NumberPoint" -> ",", "Numeric" -> True, "DateStringFormat" -> {"Year", "", "Month", "", "Day"}]

    Returns the first field as a number but it's a date. Also tried "DateStringFormat" -> {"Year", "Month", "Day"} but doesn't works...

    – crazzymath Mar 15 '12 at 12:36