Hellnar
Hellnar

Reputation: 64793

Python tar generation question

I'm creating a tar file from a directory as such /home/user/bla/mydir/

Now I want to create a tar.gz file which starts from mydir/, not having directory list of the archieve content listing starting from /home/user/bla/mydir/.

How can this be done?

Here is my original one:

tar = tarfile.open("/home/user/mytar.tar.gz", "w:gz")
    tar.add("/home/user/bla/mydir/")
    tar.close()

Upvotes: 1

Views: 372

Answers (1)

Marcelo Cantos
Marcelo Cantos

Reputation: 185852

Use the add() method's arcname parameter:

tar.add("/home/user/bla/mydir/", arcname="mydir")

Upvotes: 2

Related Questions