January 2019
Beginner
318 pages
8h 23m
English
Now, we are going to write a script called shutil_make_archive.py and write the following content in it:
import tarfileimport shutilimport sysshutil.make_archive( 'work_sample', 'gztar', root_dir='..', base_dir='work',)print('Archive contents:')with tarfile.open('work_sample.tar.gz', 'r') as t_file: for names in t_file.getnames(): print(names)
Run the program and you'll get the following output:
$ python3 shutil_make_archive.pyArchive contents:workwork/bye.pywork/shutil_make_archive.pywork/welcome.pywork/hello.py
In the preceding example, to create an archive file, we used the shutil and tarfile modules of Python. In shutil.make_archive(), we specified work_sample, which will be the name of the archive file and will be in ...
Read now
Unlock full access