[Tutor] How to skip a single file when using shutil.make_archive()
papillion at gmail.com
Sat Aug 15 00:57:47 CEST 2015
Many thanks Ben! That is exactly what I was looking for and it's super
easy. Thanks again!
On Fri, Aug 14, 2015 at 5:36 PM, Ben Finney <ben+python at benfinney.id.au>
> Anthony Papillion <papillion at gmail.com> writes:
> > I'm creating an archive of a directory using shutil.make_archive and
> > need to skip a single file if it is present in that directory. Is
> > there a way to do this or should I be looking to ZipFile to meet this
> > need?
> You can create a hierarchy of files the way you want it, and then use
> ‘shutil.make_archive’ once the tree is the way you want it.
> * Use ‘tempfile.mkdtemp’ to create a unique temporary working directory,
> and bind its name to ‘working_dir’.
> * Use ‘shutil.copytree’ to copy the entire hierarchy from its permanent
> location to the temporary ‘working_dir’ location.
> * Use other ‘shutil’ functions to manipulate the files in ‘working_dir’
> the way you want.
> * Use ‘shutil.make_archive’ to create an archive of the files from
> * Use ‘shutil.rmtree’ to remove the ‘working_dir’.
> \ “All television is educational television. The question is: |
> `\ what is it teaching?” —Nicholas Johnson |
> _o__) |
> Ben Finney
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
More information about the Tutor