从R中受密码保护的zip文件夹中提取文件

时间:2019-04-09 10:56:22

标签: r

我正在尝试在REMOTE服务器中解压缩某些.zip文件。 我尝试了Kim建议的确切步骤,并将7z修改为zip。

Unzip password protected zip files in R

但是,它不适用于我。知道哪里出了问题吗?

file_list <- list.files(path = "C:/Users/Username/Documents", pattern = ".zip", all.files = T)

pw = readline(prompt = "Enter the password: ")

for (file in file_list) {
sys_command = paste0("unzip ", "-P ", pw, " ", file)
system(sys_command)

}

我有一个名为“ Data Science Lifecycle.zip”的zip文件。

谢谢!

1 个答案:

答案 0 :(得分:0)

已成功解压缩.7z和.zip格式的受密码保护的文件。

system("7z x test.7z -ptest") #working for .7z extension files, pw: test
system("7z x test.zip -ptest") #working for .zip extension files, pw: test

我错过了其中一个步骤,即将7-Zip程序添加到R PATH。

if(dir.exists("C:/Program Files/7-Zip/")) 
{   
    paste0("7-Zip exists!")
    old_path <- Sys.getenv("PATH")
    Sys.setenv(PATH = paste(old_path,"C:\\Program Files\\7-Zip\\", sep = ""))
}

参考网址:

  1. r system doesn't work when trying 7zip

  2. https://community.rstudio.com/t/adding-to-the-path-variable/12066

希望有帮助!