修改OP配置文件IP

import os
 
# ask the user for the old and new values
oldValue = input("Enter the old value: ")
newValue = input("Enter the new value: ")
basePath = "/opt/genshin-server/"
# ask the user for the list of files
files = basePath + "genshin/srv/nodeserver/conf/nodeserver.xml," + basePath + "genshin/srv/gateserver/conf/gateserver.xml," + basePath + "genshin/srv/dbgate/conf/dbgate.xml," + basePath + "genshin/srv/dispatch/conf/dispatch.xml," + basePath + "genshin/srv/gameserver/conf/gameserver.xml," + basePath + "genshin/srv/muipserver/conf/muipserver.xml," + basePath + "genshin/srv/oaserver/conf/oaserver.xml," + basePath + "genshin/srv/pathfindingserver/conf/pathfindingserver.xml," + basePath + "genshin/srv/multiserver/conf/multiserver.xml," + basePath + "genshin/srv/tothemoonserver/conf/tothemoonserver.xml," + basePath + "genshin/srv/sdkserver/config.json"
 
# split the list of files into a list of filenames
filenames = files.split(",")
 
# iterate over the list of filenames
for filename in filenames:
  # check if the file exists and is readable
  if os.path.isfile(filename) and os.access(filename, os.R_OK):
    # open the file in read-only mode
    with open(filename, 'r') as f:
      # read the file content
      content = f.read()
 
      # replace the old value with the new value
      content = content.replace(oldValue, newValue)
 
      # open the file in write-only mode
      with open(filename, 'w') as f:
        # write the new content to the file
        f.write(content)
 
        # print a confirmation message
        print(f"The file '{filename}' was successfully updated.")
  else:
    # print an error message
    print(f"Error: the file '{filename}' does not exist or is not readable.")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值