1. 程式人生 > >Python判斷檔案路徑是否存在exists()

Python判斷檔案路徑是否存在exists()

# -*- coding:utf-8 -*-
from sys import argv
from os.path 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()