So I need to access the files and the folders within the zipped folder(also tar). The user gives the path where this Gunzip file is present and from the python code, I need to unzip, untar and extract all these files to the same location and then access the files and folders within this directory.
path given by user - C:/Users/user1/Desktop/tar_gz/tarball.tar.xz
the files should be extracted to the same directory - C:/Users/user1/Desktop/tar_gz/tarball
I'm new to the concepts of machine learning and having a difficult time figuring this out. Is there any approach to do this?
Python tarfile module
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 directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With