How can files be added to a tarfile with Python, without adding the directory hierarchy?

前端 未结 4 1992
甜味超标
甜味超标 2020-12-13 05:30

When I invoke add() on a tarfile object with a file path, the file is added to the tarball with directory hierarchy associated. In other words, if

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-13 06:17

    Maybe you can use the "arcname" argument to TarFile.add(name, arcname). It takes an alternate name that the file will have inside the archive.

提交回复
热议问题