我有一个 R 脚本(pdf、csv 文件)的输出目录,我想在每次运行代码时对其进行压缩(从 utils 包中压缩)。
>path_out
I:\\full\\path\\to\\file\\
>files2zip <- dir(path_out, full.names = TRUE)
>zip(zipfile = paste(path_out,unitList[ii],"_",Sys.Date(),sep=""), files = files2zip)
Run Code Online (Sandbox Code Playgroud)
这会痛苦地生成一个 zip 文件,文件中包含完整路径目录:
>unzip(zipfile = paste(path_out,unitList[ii],"_",Sys.Date(),".zip",sep=""), list = TRUE, junkpaths = FALSE)
Date
/full/path/to/file/file1.pdf 7978 2018-04-16 13:44:00
/full/path/to/file/file2.pdf 6665 2018-04-16 09:14:00
/full/path/to/file/file3.pdf 6557 2018-04-15 11:22:00
/full/path/to/file/file4.csv 627 2018-03-27 11:10:00
Run Code Online (Sandbox Code Playgroud)
在 Bash zip 中有一个 -j 标签,它会破坏完整路径并且只包含相对路径。有没有办法在R中做到这一点?
seh*_*ock 11
您可以使用函数extras的参数zip()。
所以:
zip(zipfile = paste(path_out,unitList[ii],"_",Sys.Date(),sep=""), files = files2zip, extras = '-j')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
498 次 |
| 最近记录: |