在 Python 中剪切和粘贴文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26443871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 00:28:33 来源:igfitidea点击:
Cut and Paste a File or Directory in Python
提问by Ryan
I need to move a lot of data to different locations on one drive, so cutting and pasting would be much faster. Currently, I'm just using shutil.copytree and shutil.rmtree, which works but it's slow.
我需要将大量数据移动到一个驱动器上的不同位置,因此剪切和粘贴会更快。目前,我只使用了shutil.copytree 和shutil.rmtree,它可以工作,但速度很慢。
Is there any way to cut/paste files instead of copy/delete?
有没有办法剪切/粘贴文件而不是复制/删除?
采纳答案by Adem ?zta?
>>> import shutil
>>> shutil.move(source, destination)
>>> import os
>>> os.rename(source, destination)

