您好我正在尝试使用R来控制解压缩文件。
我在PATH中添加了7z,并且
7z e hat.2015-09-26T01-10-02.gz
并且有效。
现在在R中,我在同一个目录中,我试过
> command1 = paste0('7z e ', drop.file)
> command1
[1] "7z e hat.2015-09-26T01-10-02.gz"
> system(command1, intern=T)
Error in system(command1, intern = T) : '7z' not found
> system2(command1)
Warning message:
running command '"7z e hat.2015-09-26T01-10-02.gz"' had status 127
> shell(command1)
'7z' is not recognized as an internal or external command,
operable program or batch file.
Warning messages:
1: running command 'C:\Windows\system32\cmd.exe /c 7z e hat.2015-09-26T01-10-02.gz' had status 1
2: In shell(command1) :
'7z e hat.2015-09-26T01-10-02.gz' execution failed with error code 1
答案 0 :(得分:0)
它有点生,但尝试一下(:
仅限Windows。它使用CMD
ZiparEm7zip = function(sQualPasta)
{
sWDTava = getwd()
setwd(dirname(sQualPasta))
sQuem = gsub("[/]", "\\\\", sQualPasta)
dirname(sQuem)
NomeArquivo = paste0("eufaco7zip",".bat")
sNomePasta7zip = basename(sQuem)
sArquivoSaida = basename(sQuem)
sQualPasta7zip = sQuem
if(dir.exists("C:/Program Files/7-Zip/"))
{
sTexto = "set PATH=%PATH%;C:\\Program Files\\7-Zip\\"
}else if(dir.exists("C:/Program Files (x86)/7-Zip/"))
{
sTexto = "set PATH=%PATH%;C:\\Program Files (x86)\\7-Zip\\"
}else
{
stop("Error, o 7zip not installed?")
}
sTexto2 = paste0("\npushd ",sQualPasta7zip)
sTexto3 = paste0("\n7z a -r ../",sArquivoSaida," *")
sTexto4 = '\n( del /q /f "%~f0" >nul 2>&1 & exit /b 0 )'
cat(sTexto,file=NomeArquivo,append = TRUE)
cat(sTexto2,file=NomeArquivo,append = TRUE)
cat(sTexto3,file=NomeArquivo,append = TRUE)
cat(sTexto4,file=NomeArquivo,append = TRUE)
shell.exec(NomeArquivo)
while(file.exists(NomeArquivo))
{
Sys.sleep(10)
}
setwd(sWDTava)
return(TRUE)
}
尝试:
ZiparEm7zip("F:/MYFOLDER")