Download and Unzip a file

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Download and Unzip a file

himanshuy
Hi

I am trying to download and unzip a zip file from the following location.

http://www.nseindia.com/content/historical/DERIVATIVES/2011/DEC/fo08DEC2011bhav.csv.zip

I initially there was issue with useragent so i ran the following code

options(HTTPUserAgent="Firefox/8.0.1")
u = "http://www.nseindia.com/content/historical/DERIVATIVES/2011/DEC/fo08DEC2011bhav.csv.zip"
o = getURLContent(u, verbose = TRUE, useragent = getOption("HTTPUserAgent"))

now I want to unzip and save this file. I was initially working on matlab and have recently moved to R.
any help would be much appreciated.

Thanks
Himanshu Y
Reply | Threaded
Open this post in threaded view
|

Re: Download and Unzip a file

Michael Weylandt
Do unz / unzip get the job done?

Michael

On Wed, Dec 14, 2011 at 8:19 AM, himanshuy <[hidden email]> wrote:

> Hi
>
> I am trying to download and unzip a zip file from the following location.
>
> http://www.nseindia.com/content/historical/DERIVATIVES/2011/DEC/fo08DEC2011bhav.csv.zip
>
> I initially there was issue with useragent so i ran the following code
>
> options(HTTPUserAgent="Firefox/8.0.1")
> u =
> "http://www.nseindia.com/content/historical/DERIVATIVES/2011/DEC/fo08DEC2011bhav.csv.zip"
> o = getURLContent(u, verbose = TRUE, useragent = getOption("HTTPUserAgent"))
>
> now I want to unzip and save this file. I was initially working on matlab
> and have recently moved to R.
> any help would be much appreciated.
>
> Thanks
> Himanshu Y
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Download-and-Unzip-a-file-tp4194895p4194895.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Download and Unzip a file

himanshuy
I tried using unzip but it gave the following error "Invalid zip name argument"

options(HTTPUserAgent="Firefox/8.0.1")
u = "http://www.nseindia.com/content/historical/DERIVATIVES/2011/DEC/fo08DEC2011bhav.csv.zip"
o = getURLContent(u, verbose = TRUE, useragent = getOption("HTTPUserAgent"))

after this I ran the unzip
unzip(o , files = NULL, list = FALSE, overwrite = TRUE, junkpaths = FALSE, exdir = "D:\\", unzip = "internal", setTimes = FALSE)

but i got this error

Error in unzip(o, files = NULL, list = FALSE, overwrite = TRUE, junkpaths = FALSE,  :
  invalid zip name argument

Thanks
Himanshu Y