开发者

Creating zip file from folders

I am wondering if it is possible to create a zip file from folders. I have one f开发者_如何学编程older and in this folders there are four folders and in there, there are different kind of files. Now I want to zip those four folders recursively with their files.

I tried save() and gzip() but they don't do what I want.

Has someone a hint for me?


Scope out the tar command. While it's not zip, a compressed tar file is just as good.

tarfile <- 'newfile.tgz'
tar(tarfile,'/path/of/dir/to/tar/up',compression='gzip')


The Rcompression package at Omegahat can do that. Here is a minimal example:

library(Rcompression)
d <- "C:/my_data"
files <- list.files(d, recursive=TRUE)
zip("myarchive.zip", files=paste(d, files, sep="/"), altNames=files)

See ?zip for more examples.


You could look for tips in the sources of odfWeave package.

If you load the library and type odfWeave, you will get the source, which is not too long and implements zipping and unzipping also with system calls.

From theese sources, you could do something like:

filename = '' # set archive filename
loc = ''      # set location, if not done before
setwd(loc)
zipCmd = paste("zip -r ", filename, " .", sep='')
system(zipCmd, invisible = TRUE) 

Of course, zip must be installed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜