Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
e9ce0b0f
Kaydet (Commit)
e9ce0b0f
authored
Eki 07, 2002
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch #448038: Add move(). Report errors from copytree as in shutil.Error.
üst
114619e1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
2 deletions
+49
-2
libshutil.tex
Doc/lib/libshutil.tex
+16
-0
shutil.py
Lib/shutil.py
+30
-2
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/lib/libshutil.tex
Dosyayı görüntüle @
e9ce0b0f
...
...
@@ -93,6 +93,22 @@ file type and creator codes will not be correct.
not be caught.
\end{funcdesc}
\begin{funcdesc}
{
move
}{
src, dst
}
Recursively move a file or directory to another location.
If the destination is on our current filesystem, then simply use
rename. Otherwise, copy src to the dst and then remove src.
\versionadded
{
2.3
}
\end{funcdesc}
\begin{excdesc}
{
Error
}
This exception collects exceptions that raised during a mult-file
operation. For
\function
{
copytree
}
, the exception argument is a
list of 3-tuples (
\var
{
srcname
}
,
\var
{
dstname
}
,
\var
{
exception
}
).
\versionadded
{
2.3
}
\end{excdesc}
\subsection
{
Example
\label
{
shutil-example
}}
...
...
Lib/shutil.py
Dosyayı görüntüle @
e9ce0b0f
...
...
@@ -7,9 +7,13 @@ XXX The functions here don't copy the resource fork or other metadata on Mac.
import
os
import
sys
import
stat
import
exceptions
__all__
=
[
"copyfileobj"
,
"copyfile"
,
"copymode"
,
"copystat"
,
"copy"
,
"copy2"
,
"copytree"
,
"rmtree"
]
"copytree"
,
"rmtree"
,
"Error"
]
class
Error
(
exceptions
.
EnvironmentError
):
pass
def
copyfileobj
(
fsrc
,
fdst
,
length
=
16
*
1024
):
"""copy data from file-like object fsrc to file-like object fdst"""
...
...
@@ -95,6 +99,7 @@ def copytree(src, dst, symlinks=0):
"""
names
=
os
.
listdir
(
src
)
os
.
mkdir
(
dst
)
errors
=
[]
for
name
in
names
:
srcname
=
os
.
path
.
join
(
src
,
name
)
dstname
=
os
.
path
.
join
(
dst
,
name
)
...
...
@@ -108,7 +113,9 @@ def copytree(src, dst, symlinks=0):
copy2
(
srcname
,
dstname
)
# XXX What about devices, sockets etc.?
except
(
IOError
,
os
.
error
),
why
:
print
"Can't copy
%
s to
%
s:
%
s"
%
(
`srcname`
,
`dstname`
,
str
(
why
))
errors
.
append
((
srcname
,
dstname
,
why
))
if
errors
:
raise
Error
,
errors
def
rmtree
(
path
,
ignore_errors
=
0
,
onerror
=
None
):
"""Recursively delete a directory tree.
...
...
@@ -141,3 +148,24 @@ def _build_cmdtuple(path, cmdtuples):
else
:
cmdtuples
.
append
((
os
.
remove
,
real_f
))
cmdtuples
.
append
((
os
.
rmdir
,
path
))
def
move
(
src
,
dst
):
"""Recursively move a file or directory to another location.
If the destination is on our current filesystem, then simply use
rename. Otherwise, copy src to the dst and then remove src.
A lot more could be done here... A look at a mv.c shows a lot of
the issues this implementation glosses over.
"""
try
:
os
.
rename
(
src
,
dst
)
except
OSError
:
if
os
.
path
.
isdir
(
src
):
copytree
(
src
,
dst
,
symlinks
=
1
)
rmtree
(
src
)
else
:
copy2
(
src
,
dst
)
os
.
unlink
(
src
)
Misc/NEWS
Dosyayı görüntüle @
e9ce0b0f
...
...
@@ -342,6 +342,9 @@ Extension modules
Library
-------
-
shutil
.
move
was
added
.
shutil
.
copytree
now
reports
errors
as
an
exception
at
the
end
,
instead
of
printing
error
messages
.
-
Encoding
name
normalization
was
generalized
to
not
only
replace
hyphens
with
underscores
,
but
also
all
other
non
-
alphanumeric
characters
(
with
the
exception
of
the
dot
which
is
used
for
Python
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment