python,需要实现copy一个文件到指定目录,并设为隐藏文件

如题所述

import platform, locale, os, time, shutil

def hideFile(filePath):
    if 'Windows' in platform.system():
        cmd = 'attrib +h "' + filePath +'"'
        cmd = cmd.encode(locale.getdefaultlocale()[1])
        os.popen(cmd).close()
        time.sleep(1)

def copyFile(fromPath, toPath):
    f = open(fromPath, 'rb')
    t = open(toPath, 'wb+')
    shutil.copyfileobj(fsrc=f, fdst=t, length=1024 * 16)
    f.close()
    t.close()
    hideFile(toPath)

温馨提示:答案为网友推荐,仅供参考