因此,我需要访问压缩文件夹(也是tar)中的文件和文件夹。用户给出了这个Gunzip文件所在的路径,从python代码中,我需要将所有这些文件解压缩、解压并解压到相同的位置,然后访问这个目录中的文件和文件夹。
path given by user - C:/Users/user1/Desktop/tar_gz/tarball.tar.xz应将这些文件解压缩到同一目录- C:/Users/user1/Desktop/tar_gz/tarball
我刚接触机器学习的概念,并且很难弄清楚这一点。有什么方法可以做到这一点吗?
发布于 2020-10-07 15:36:32
import tarfile
import os
path_tofile = r"C:/Users/user1/Desktop/tar_gz/tarball.tar.xz"
extract_direcotry = os.path.dirname(path_tofile)
if tarfile.is_tarfile(path_tofile):
with tarfile.open(path_tofile) as f:
f.extractall(path=extract_direcotry) # Extract all members from the archive to the current working directoryhttps://stackoverflow.com/questions/64238934
复制相似问题