【问题标题】:Extract files from password protected zip folder in R从 R 中受密码保护的 zip 文件夹中提取文件
【发布时间】:2019-04-09 10:56:21
【问题描述】:

我正在尝试在远程服务器中解压缩一些 .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 文件。

提前致谢!

【问题讨论】:

  • 可能是空间问题?试试把名字改成Data_Science_Lifecycle.zip
  • 过去我在文件路径中遇到过空格问题。尝试将文件路径/文件名放在引号中,如下所示:example &lt;- "\"my archive.zip\""
  • 你可以打印(sys_command)并在windows终端运行看看是否正常?

标签: r


【解决方案1】:

设法解压缩 .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

希望对你有帮助!

【讨论】:

  • 试过了,但出现错误 127。在您的示例中,test.zip 位于哪里?
猜你喜欢
  • 1970-01-01
  • 2012-05-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-06
  • 1970-01-01
  • 1970-01-01
  • 2014-12-16
相关资源
最近更新 更多