Mis a jour le 2025-04-14, 12:10

Archives tar

Lecture d'un tar.gz :
  • import tarfile; tarFile = tarfile.open('myFile.tar.gz', mode = 'r:gz') : renvoie un objet TarFile
  • pour lire un tar et extraire les fichiers, dans un directory donné /otherPath (sinon, par défaut, c'est dans le directory courant) :
    tarInfo = tarFile.next()
    while tarInfo is not None:
      print(tarInfo.name)
      tarFile.extract(tarInfo, path = '/otherPath')
      tarInfo = tarFile.next()
    tarInfo.close()
        

Copyright python-simple.com
programmer en python, tutoriel python, graphes en python, Aymeric Duclert