首页 > 试题广场 >

3 [问答]使用shutil模块中的move()方法进行文件

[问答题]
使用shutil模块中的move()方法进行文件移动。
#!/usr/bin/python3

import shutil
import os

def move(src, dst):
    from_file_path = src
    to_file_path = dst

    if os.path.exists(from_file_path):
        if os.path.exists(to_file_path):
            shutil.move(from_file_path, to_file_path)
        else:
            print("目的路径失效,找不到指定路径")
    else:
        print("源路径文件不存在")

if __name__ == "__main__":
    move("english.txt", "/root/")

发表于 2020-06-05 23:50:34 回复(0)
import shutil
import os
file="J2010.pdf"
to_path="D:\study"
if os.path.exists(file):
    if os.path.exsits(to_path):
        shutil.move(file,to_path)
    else:
        print("No such path")
else:
    print("The file does not exist")

发表于 2020-06-29 10:54:13 回复(0)
import shutil
shutil.move(r'd:\chuangshiyuanling1.txt', r'e:\chuangshiyuanling1.txt')
发表于 2019-07-16 11:38:45 回复(0)

shutil.move(oldpath, newpath)

发表于 2019-03-17 13:25:06 回复(1)