解压缩在 R 中分成多个卷的存档

问题描述 投票:0回答:1

背景

我正在创建一个 R 脚本,它应该下载 .zip 文件,然后解压缩它们并将内容移动到目录的正确位置。

我必须将数据上传到的地方有文件大小限制的问题,因此我必须将存档分成多个卷。

例子

我正在寻找类似的东西

file <- 'myfile.zip001' # There is also 'myfile.zip002', 'myfile.zip003' and 'myfile.zip004'
unzip(file)

我刚刚在某个目录中解压了这个拆分存档。这可能吗?

PS 我不确定如何为这个制作可重现的例子。如果您有任何建议,请告诉我。

r zip unzip
1个回答
0
投票

借用这个 answer 并使用在 Mac 上使用基本 R

zip
功能拆分的文件。


# create split zip files
zip_name <- "foo.zip"

folder_path <- "folder/with/many/files"

# create zip with 100mb chunks
zip(zipfile = zip_name,
      files = list.files(folder_path,
                         full.names = T,
                         recursive = TRUE),
      flags = "-q -s 100m" )

## aggregate then unzip

# aggregate into a single zip
# -s == size of split, here we are setting it to zero so no splits
# --out == where should the files go?
# provide the file that ends in .zip to aggregate the split zip
# zip -s 0 [ZIP FILE from SPLIT] --out [AGGREGATED FILE]

agg_command <- "zip -s 0 foo.zip --out unsplit-foo.zip"

system(agg_command)

dir.create("foo_extract")

unzip(zipfile = "unsplit-foo.zip",exdir = "foo_extract")
© www.soinside.com 2019 - 2024. All rights reserved.