No title

Anonymous Coward 2018-03-04 06:20:28.05444 UTC

1import os
2import tarfile
3
4def filter_ext(tarinfo, ext):
5 return tarinfo if os.path.splitext(tarinfo.name)[1] == ext else None
6
7with tarfile.open('example.tar.bz2', 'w:bz2') as tar:
8 tar.add('example/dir', filter=lambda tarinfo: filter_ext(tarinfo, '.ext'))