问题
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.
- Use shell
- Use shQuote for surrounding path
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