|
Size: 1562
Comment:
|
← Revision 4 as of 2023-06-15 18:39:30 ⇥
Size: 1792
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 9: | Line 9: |
| == ChOwn == | == Usage == === ChOwn === |
| Line 15: | Line 17: |
| == Copy == | === Copy === |
| Line 30: | Line 32: |
| If the source and destination filenames represent the same file, `shutuil.SameFileError` is raised. |
|
| Line 36: | Line 40: |
| == Copy2 == | === Copy2 === |
| Line 44: | Line 48: |
| == CopyFile == | === CopyFile === |
| Line 67: | Line 71: |
| == CopyMode == | === CopyMode === |
| Line 73: | Line 77: |
| == CopyStat == | === CopyStat === |
| Line 79: | Line 83: |
| == CopyTree == | === CopyTree === |
| Line 85: | Line 89: |
| == Disk_Usage == | === Disk_Usage === |
| Line 91: | Line 95: |
| == Get_Archive_Formats == | === Get_Archive_Formats === |
| Line 97: | Line 101: |
| == Get_Terminal_Size == | === Get_Terminal_Size === |
| Line 103: | Line 107: |
| == Get_Unpack_Formats == | === Get_Unpack_Formats === |
| Line 109: | Line 113: |
| == Make_Archive == | === Make_Archive === |
| Line 115: | Line 119: |
| == Move == | === Move === |
| Line 121: | Line 125: |
| == RmTree == | === RmTree === |
| Line 127: | Line 131: |
| == Unpack_Archive == | === Unpack_Archive === |
| Line 133: | Line 137: |
| == Which == | === Which === |
| Line 143: | Line 147: |
| [[https://pymotw.com/3/shutil/|Python Module of the Day article for shutil]] |
Python ShUtil
Contents
Usage
ChOwn
Copy
Copy the contents of a file to another file (or directory). File permissions are also copied.
from pathlib import Path
import shutil
p = Path('.')
original = p.joinpath('build')
destination = p.joinpath('archive')
for f in original.iterdir():
shutil.copy(f, destination)If the source and destination filenames represent the same file, shutuil.SameFileError is raised.
If the destination is not writeable, OSError is raised.
Copy2
Same as copy but tries to preserve metadata.
CopyFile
Copy the contents of a file to another file. No metadata is copied.
from pathlib import Path
import shutil
p = Path('.')
original = p.joinpath('build')
destination = p.joinpath('archive')
for f in original.iterdir():
shutil.copyfile(f, destination.joinpath(f.name))If the source and destination filenames represent the same file, shutuil.SameFileError is raised.
If the destination is not writeable, OSError is raised.
CopyMode
CopyStat
CopyTree
Disk_Usage
Get_Archive_Formats
Get_Terminal_Size
Get_Unpack_Formats
Make_Archive
Move
RmTree
Unpack_Archive
Which
See also
Python shutil module documentation
Python Module of the Day article for shutil
