MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / copy_tree

Function copy_tree

tools/python-3.11.9-amd64/Lib/distutils/dir_util.py:99–166  ·  view source on GitHub ↗

Copy an entire directory tree 'src' to a new location 'dst'. Both 'src' and 'dst' must be directory names. If 'src' is not a directory, raise DistutilsFileError. If 'dst' does not exist, it is created with 'mkpath()'. The end result of the copy is that every file in 'src' is

(src, dst, preserve_mode=1, preserve_times=1,
              preserve_symlinks=0, update=0, verbose=1, dry_run=0)

Source from the content-addressed store, hash-verified

97 mkpath(dir, mode, verbose=verbose, dry_run=dry_run)
98
99def copy_tree(src, dst, preserve_mode=1, preserve_times=1,
100 preserve_symlinks=0, update=0, verbose=1, dry_run=0):
101 """Copy an entire directory tree 'src' to a new location 'dst'.
102
103 Both 'src' and 'dst' must be directory names. If 'src' is not a
104 directory, raise DistutilsFileError. If 'dst' does not exist, it is
105 created with 'mkpath()'. The end result of the copy is that every
106 file in 'src' is copied to 'dst', and directories under 'src' are
107 recursively copied to 'dst'. Return the list of files that were
108 copied or might have been copied, using their output name. The
109 return value is unaffected by 'update' or 'dry_run': it is simply
110 the list of all files under 'src', with the names changed to be
111 under 'dst'.
112
113 'preserve_mode' and 'preserve_times' are the same as for
114 'copy_file'; note that they only apply to regular files, not to
115 directories. If 'preserve_symlinks' is true, symlinks will be
116 copied as symlinks (on platforms that support them!); otherwise
117 (the default), the destination of the symlink will be copied.
118 'update' and 'verbose' are the same as for 'copy_file'.
119 """
120 from distutils.file_util import copy_file
121
122 if not dry_run and not os.path.isdir(src):
123 raise DistutilsFileError(
124 "cannot copy tree '%s': not a directory" % src)
125 try:
126 names = os.listdir(src)
127 except OSError as e:
128 if dry_run:
129 names = []
130 else:
131 raise DistutilsFileError(
132 "error listing files in '%s': %s" % (src, e.strerror))
133
134 if not dry_run:
135 mkpath(dst, verbose=verbose)
136
137 outputs = []
138
139 for n in names:
140 src_name = os.path.join(src, n)
141 dst_name = os.path.join(dst, n)
142
143 if n.startswith('.nfs'):
144 # skip NFS rename files
145 continue
146
147 if preserve_symlinks and os.path.islink(src_name):
148 link_dest = os.readlink(src_name)
149 if verbose >= 1:
150 log.info("linking %s -> %s", dst_name, link_dest)
151 if not dry_run:
152 os.symlink(link_dest, dst_name)
153 outputs.append(dst_name)
154
155 elif os.path.isdir(src_name):
156 outputs.extend(

Calls 11

DistutilsFileErrorClass · 0.90
copy_fileFunction · 0.90
listdirMethod · 0.80
startswithMethod · 0.80
readlinkMethod · 0.80
mkpathFunction · 0.70
isdirMethod · 0.45
joinMethod · 0.45
infoMethod · 0.45
appendMethod · 0.45
extendMethod · 0.45