[Tutor] How to skip a single file when using shutil.make_archive()
Ben Finney
ben+python at benfinney.id.au
Sat Aug 15 00:36:05 CEST 2015
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
‘working_dir’.
* 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
More information about the Tutor
mailing list