Python判断文件路径是否存在exists

时间:2024-10-21 11:52:38
# -*- coding:utf-8 -*-
from sys import argv
from  import exists

script,from_file,to_file = argv
print("Copying from %s to %s" % (from_file,to_file))
print("Does the destination file exists? : %s" % exists(to_file))
if exists(to_file):
    in_file = open(from_file)
    in_data = in_file.read()
    out_file = open(to_file,'w')
    out_file.write(in_data)
    in_file.close()
    out_file.close()