如何修复文件路径,以便untar()可以打开压缩?

时间:2019-08-16 01:43:25

标签: r for-loop directory subdirectory

我试图进入每个子目录并解压缩单个.tar文件,然后 将未压缩的数据放入包含.tar文件的相同子目录中。您能帮忙解决此循环吗,我不明白为什么这不起作用?

这是输出错误:

 Error in gzfile(path.expand(tarfile), "rb") : cannot open the connection
In addition: Warning message:
In gzfile(path.expand(tarfile), "rb") :
  cannot open compressed file './GSE20292 / GSE20292_RAW.tar', probable reason 'No such file or directory'

这是我尝试过的:

# get into the parent directory
setwd("filepath")
# loop through the sub directories (use [-1] to lop off the current   directory: ".")
for (dir in list.dirs()[-1]) {
# get into the sub directory
    #setwd(dir)
# do the do
temp <- list.files(dir, pattern="*.tar")
untar(paste(dir, "/", temp), exdir = dir)
    # pop back up to the parent directory
setwd("../")
};

0 个答案:

没有答案