<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"dist.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index'
/>
<link rel=
"first" href=
"dist.html" title='Distributing Python Modules'
/>
<link rel='index' href='genindex.html' title='Index'
/>
<link rel='last' href='about.html' title='About this document...'
/>
<link rel='help' href='about.html' title='About this document...'
/>
<link rel=
"next" href=
"module-distutils.fileutil.html" />
<link rel=
"prev" href=
"module-distutils.deputil.html" />
<link rel=
"parent" href=
"api-reference.html" />
<link rel=
"next" href=
"module-distutils.fileutil.html" />
<meta name='aesop' content='information'
/>
<title>10.11 distutils.dir_util -- Directory tree operations
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"10.10 distutils.dep_util "
href=
"module-distutils.deputil.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"10. API Reference"
href=
"api-reference.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"10.12 distutils.file_util "
href=
"module-distutils.fileutil.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Distributing Python Modules
</td>
<td class='online-navigation'
><img src='../icons/blank.png'
border='
0' height='
32' alt='' width='
32'
/></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"module-distutils.deputil.html">10.10 distutils.dep_util
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"api-reference.html">10. API Reference
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"module-distutils.fileutil.html">10.12 distutils.file_util
</A>
<!--End of Navigation Panel-->
<H1><A NAME=
"SECTION00101100000000000000000">
10.11 <tt class=
"module">distutils.dir_util
</tt> -- Directory tree operations
</A>
<A NAME=
"module-distutils.dirutil"></A>
This module provides functions for operating on directories and trees
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
70' xml:id='l2h-
70'
class=
"function">mkpath
</tt></b>(
</nobr></td>
<td><var>name
</var><big>[
</big><var>, mode=
<code>0777</code>, verbose=
<code>0</code>, dry_run=
<code>0</code></var><big>]
</big><var></var>)
</td></tr></table></dt>
Create a directory and any missing ancestor directories. If the
directory already exists (or if
<var>name
</var> is the empty string, which
means the current directory, which of course exists), then do
nothing. Raise
<tt class=
"exception">DistutilsFileError
</tt> if unable to create some
directory along the way (eg. some sub-path exists, but is a file
rather than a directory). If
<var>verbose
</var> is true, print a one-line
summary of each mkdir to stdout. Return the list of directories
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
71' xml:id='l2h-
71'
class=
"function">create_tree
</tt></b>(
</nobr></td>
<td><var>base_dir, files
</var><big>[
</big><var>, mode=
<code>0777</code>, verbose=
<code>0</code>, dry_run=
<code>0</code></var><big>]
</big><var></var>)
</td></tr></table></dt>
Create all the empty directories under
<var>base_dir
</var> needed to
put
<var>files
</var> there.
<var>base_dir
</var> is just the a name of a directory
which doesn't necessarily exist yet;
<var>files
</var> is a list of filenames
to be interpreted relative to
<var>base_dir
</var>.
<var>base_dir
</var> + the
directory portion of every file in
<var>files
</var> will be created if it
doesn't already exist.
<var>mode
</var>,
<var>verbose
</var> and
<var>dry_run
</var> flags
are as for
<tt class=
"function">mkpath()
</tt>.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
72' xml:id='l2h-
72'
class=
"function">copy_tree
</tt></b>(
</nobr></td>
<td><var>src, dst
</var><big>[
</big><var>preserve_mode=
<code>1</code>, preserve_times=
<code>1</code>, preserve_symlinks=
<code>0</code>, update=
<code>0</code>, verbose=
<code>0</code>, dry_run=
<code>0</code></var><big>]
</big><var></var>)
</td></tr></table></dt>
Copy an entire directory tree
<var>src
</var> to a new location
<var>dst
</var>. Both
<var>src
</var> and
<var>dst
</var> must be directory names. If
<var>src
</var> is not a
directory, raise
<tt class=
"exception">DistutilsFileError
</tt>. If
<var>dst
</var> does
not exist, it is created with
<tt class=
"function">mkpath()
</tt>. The end result of the
copy is that every file in
<var>src
</var> is copied to
<var>dst
</var>, and
directories under
<var>src
</var> are recursively copied to
<var>dst
</var>.
Return the list of files that were copied or might have been copied,
using their output name. The return value is unaffected by
<var>update
</var>
or
<var>dry_run
</var>: it is simply the list of all files under
<var>src
</var>,
with the names changed to be under
<var>dst
</var>.
<var>preserve_mode
</var> and
<var>preserve_times
</var> are the same as for
<tt class=
"function">copy_file
</tt> in
<tt class=
"module"><a href=
"module-distutils.fileutil.html">distutils.file_util
</a></tt>;
note that they only apply to regular files, not to directories. If
<var>preserve_symlinks
</var> is true, symlinks will be copied as symlinks
(on platforms that support them!); otherwise (the default), the
destination of the symlink will be copied.
<var>update
</var> and
<var>verbose
</var> are the same as for
<tt class=
"function">copy_file()
</tt>.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
73' xml:id='l2h-
73'
class=
"function">remove_tree
</tt></b>(
</nobr></td>
<td><var>directory
</var><big>[
</big><var>verbose=
<code>0</code>, dry_run=
<code>0</code></var><big>]
</big><var></var>)
</td></tr></table></dt>
Recursively remove
<var>directory
</var> and all files and directories underneath
it. Any errors are ignored (apart from being reported to
<code>sys.stdout
</code> if
<var>verbose
</var> is true).
<b class=
"du-xxx">Some of this could be replaced with the shutil module?
</b>
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"10.10 distutils.dep_util "
href=
"module-distutils.deputil.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"10. API Reference"
href=
"api-reference.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"10.12 distutils.file_util "
href=
"module-distutils.fileutil.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Distributing Python Modules
</td>
<td class='online-navigation'
><img src='../icons/blank.png'
border='
0' height='
32' alt='' width='
32'
/></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"module-distutils.deputil.html">10.10 distutils.dep_util
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"api-reference.html">10. API Reference
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"module-distutils.fileutil.html">10.12 distutils.file_util
</A>
<span class=
"release-info">Release
2.4.2, documentation updated on
28 September
2005.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.