python 自动复制脚本代码

本文介绍了一种通过Python脚本来实现自动批量更新Lua脚本的方法,适用于需要在多个服务器上同步更新Lua脚本的游戏开发场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

服务器脚本发布时,如果是分服的,有多个服务器,更新一个脚本,一个个地复制粘贴,很麻烦,写个脚本自动发布,再热更新就可以,记录一下 以后用


import os;
import os.path;
import shutil;
def copyFiles(sourceDir, targetDir):
    for files in os.listdir(sourceDir):
        sourceFile = os.path.join(sourceDir, files);
        targetFile = os.path.join(targetDir, files);
        if os.path.isfile(sourceFile) and sourceFile.find('.lua'):
            tmpStr = 'cp %s %s' % (sourceFile, targetFile);
            print(tmpStr);
            shutil.copy(sourceFile, targetFile);


if __name__ == '__main__':
    copyFiles('/home/luafile', '/home/buyugameserver/lua');
    copyFiles('/home/luafile', '/home/buyu2/lua');
    copyFiles('/home/luafile', '/home/buyu3/lua');
    copyFiles('/home/luafile', '/home/buyu4/lua');
     copyFiles('/home/luafile', '/home/buyu5/lua');



上传要更新的脚本到/home/luafile 目录下,再 python3 copy_lua.py 就可以自动复制

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值