python获取绝对路径复制文件

import shutil
import sys
import os
def cur_file_dir():
    path = sys.path[0]
    if os.path.isdir(path):
        return path
    elif os.path.isfile(path):
        return os.path.dirname(path)
def path(p):
    return os.path.normpath(os.path.join(cur_file_dir(), p))

shutil.copyfile(path("22.txt"), path("33.txt"))

#file = ["xl_decrypt.cpp", "xl_decrypt.h", "xl_lzma.h", "xl_lzma.cpp", "xl_machine.cpp", \ "xl_machine.h"] 
#for one in file: s = "..\\ServerGui\\" + one 
#shutil.copyfile(path(one), path(s))  

 

posted on 2025-11-29 20:16  lydstory  阅读(0)  评论(0)    收藏  举报

导航