尝试 7zip 时系统不工作 [英] r system doesn't work when trying 7zip

查看:30
本文介绍了尝试 7zip 时系统不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 R 来控制解压缩文件.

Hi I'm trying to use R to control unzipping a file.

我已将 7z 添加到 PATH 中,并且确实

I've added 7z into PATH, and did

7z e hat.2015-09-26T01-10-02.gz

它奏效了.

现在在 R 中,我在同一个目录中,我尝试了

Now in R, i'm in the same directory, and i tried

> 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

推荐答案

它有点原始,但试试这个 (:

It's little bit raw, but try this out (:

只有 Windows.它使用 CMD

Only Windows. It's uses 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")

这篇关于尝试 7zip 时系统不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆