修改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.")

你可能感兴趣的:(java,前端,linux)