import os,shutil def mycopyfile(srcfile,dstfile): if not os.path.isfile(srcfile): print ("%s not exist!"%(srcfile)) else: fpath=os.path.dirname(srcfile) #獲取文件路徑 if not os.path.exists(fpath): os.makedirs(fpath) #沒有就創建路徑 shutil.copyfile(srcfile,dstfile) #復制文件到默認路徑 print ("copy %s -> %s"%( srcfile,os.path.join(fpath,dstfile))) mycopyfile(r'/home/tarena/PycharmProjects/untitled/day8_21/text.py','text33.py')