unpacking rar with R system()

三世轮回 提交于 2020-01-02 07:21:11

问题


OK this task seems to be really easy to do. However I spent a couple of hours without any results.

User have:

  • 7z
  • Windows
  • R

User should enter:

  • path to 7z (z7path)
  • filename

System should unpack rar into the project's root

I tried:

cmd = "C:\\Program Files (x86)\\7-Zip\\7z e D:/20140601.rar"
system(shQuote(cmd))

And..nothing happens. Please don't advise to set up PATH, it doesn't help, and this should work without it.


回答1:


Ok, I finally got it.

  1. Use shell
  2. Use shQuote for surrounding path
  3. Use right keys

    z7path = shQuote('C:\\Program Files (x86)\\7-Zip\\7z')
    file = paste(getwd(), '/101-01.rar', sep = '')
    cmd = paste(z7path, ' e ', file, ' -y -o', getwd(), '/', sep='')
    shell(cmd)
    



回答2:


I had to modify the code from the second answer, and finally it works. You can change "-ir!. -o" by "-y -o" if you want all files.

z7path = shQuote('C:\\Program Files\\7-Zip\\7z')
file = paste('"', 'D:/20140601.rar', '"',sep = '')
cmd = paste(z7path, ' e ', file, ' -ir!*.* -o', '"', getwd(), '"', sep='')

system(cmd)


来源:https://stackoverflow.com/questions/24632421/unpacking-rar-with-r-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!