tags:

views:

36

answers:

1

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()
+2  A: 

Use the add() method's arcname parameter:

tar.add("/home/user/bla/mydir/", arcname="mydir")
Marcelo Cantos
works like a charm! Thanks!
Hellnar