5,337
edits
Line 72: | Line 72: | ||
if exc.errno != errno.EEXIST: | if exc.errno != errno.EEXIST: | ||
raise | raise | ||
</syntaxhighlight> | |||
====Copying or moving a file or folder==== | |||
[https://stackoverflow.com/questions/123198/how-do-i-copy-a-file-in-python/30359308 Copying]<br> | |||
[https://docs.python.org/3.7/library/shutil.html Shutil docs] | |||
<syntaxhighlight lang="python"> | |||
import shutil | |||
# Copy a file | |||
shutil.copy2('original.txt', 'duplicate.txt') | |||
# Move a file | |||
shutil.move('original.txt', 'my_folder/original.txt') | |||
</syntaxhighlight> | </syntaxhighlight> | ||