2

I am trying to unzip some .zip files in REMOTE server. I have tried the exact steps suggested by Kim, and modified 7z to zip.

Unzip password protected zip files in R

However, it does not work for for me. Any idea where went wrong?

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)

}

I have a zip file called "Data Science Lifecycle.zip".

Thanks in advance!

kchuying
  • 83
  • 1
  • 7
  • probably space problems? Try changing the name to `Data_Science_Lifecycle.zip`? – M.K Apr 09 '19 at 10:58
  • I've had problems with spaces in filepaths in the past. Try puttingthe filepath/filename into quotes, like this: `example <- "\"my archive.zip\""` – f.lechleitner Apr 09 '19 at 11:02
  • You can print(sys_command) and run at the windows terminal and see if it was working fine? – Sonny Apr 09 '19 at 11:12

1 Answers1

1

Managed to unzip .7z & .zip format password protected files.

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

I have missed out one of the steps, which is to add 7-Zip program to 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 = ""))
}

Reference URL:

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

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

Hope it helps!

kchuying
  • 83
  • 1
  • 7