Creating an archive using shutil.make_archive (), with the exception of some paths (paths)

Is there a way to have shutil.make_archivesome child directories excluded or, alternatively, is there a way to add directories to a single archive through shutil?

Examples are funny :

/root
  /workingDir
      /dir1
      /dir2
          /dirA
          /dirB
      /dir3   

Suppose I wanted to create an archive from workingDirthat included everything except dirA- how could I do this? Is this possible if you did not write a method for cyclic movement throughout the tree?

+4
source share
1 answer

, shutil. tarfile ( )

Tarfile.add , .

. : tar Python

EXCLUDE_FILES = ['dir2/dirA']
tar = tarfile.open("sample.tar.gz", "w:gz")
tar.add("workingDir", filter=lambda x: None if x.name in EXCLUDE_FILES else x)
tar.close()
+2

Source: https://habr.com/ru/post/1650844/


All Articles