[R] How unzip all files?

Uwe Ligges ligges at statistik.tu-dortmund.de
Mon Jul 11 17:54:31 CEST 2011



On 11.07.2011 10:49, AnaA wrote:
> Hi
> I'm starting to use R in windows. I need unzip some files. Each of them are
> in different folders and subfolders. Names of folders have the same
> beginning of the name. [example:( ~ / M_ /P_ (...)/ (...)R(...)/*.zip)] I do
> not know the expression (character) necessary to call this direction and to
> unzip files are in each subfolder.

I'd start to list the files as in (all untested!):

files <- list.files(path = "~/M_", recursive=TRUE, full.names=TRUE)
files <- grep("/P_/.*/.*R.*/.*\\.zip$", files, value=TRUE)

and then iterate over files and run unzip() on each file in files with 
an appropriate exdir, e.g.:

sapply(files, function(i) unzip(i, exdir=gsub("\\.zip$", "", i))


Uwe Ligges



> Thank you.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/How-unzip-all-files-tp3658989p3658989.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org 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.



More information about the R-help mailing list