Guest User

abc

a guest
Mar 19th, 2024
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.57 KB | Gaming | 0 0
  1. import os
  2.  
  3. def process_ini_file(file_path):
  4.    
  5.     # Skip files with "_edit" in the file name
  6.     if "_edit" in file_path:
  7.         print('Skipping ' + file_path + " because its _edit suffix.")
  8.         return
  9.  
  10.     # Read the content of the ini file
  11.     with open(file_path, 'r') as f:
  12.         lines = f.readlines()
  13.  
  14.     # Initialize a list to store updated lines
  15.     updated_lines = []
  16.  
  17.     # Initialize variables to store the last two lines
  18.     prev_line = None
  19.     current_line = None
  20.  
  21.     # Iterate through each line
  22.     for i in range(len(lines)):
  23.         line = lines[i].strip()
  24.  
  25.         # Store the current line as the previous line
  26.         prev_line = current_line
  27.         current_line = line
  28.  
  29.         # Check if the line starts with "Outfit"
  30.         if line.startswith("Outfit"):
  31.             # Prompt the user for input
  32.             user_input = input(f"Enter a new Chance Value for {current_line} (type 'stop' to finish): ")
  33.  
  34.             # Check if the user wants to stop
  35.             if user_input.lower() == "stop":
  36.                 break
  37.  
  38.             # Split the line by "|"
  39.             parts = current_line.split("|")
  40.  
  41.             # Update the last number (assuming it's the last part)
  42.             try:
  43.                 parts[-1] = str(int(user_input))  # Convert user input to an integer
  44.             except ValueError:
  45.                 print("Invalid input. Please enter a valid number.")
  46.                 continue
  47.  
  48.             # Join the parts back together
  49.             updated_line = "|".join(parts)
  50.  
  51.             # Append updated line to the list
  52.             updated_lines.append(updated_line)
  53.         else:
  54.             # Print the comment line in the console
  55.             if line.startswith(";"):
  56.                 print(f"Comment: {line[1:]}")
  57.  
  58.             # Append other lines as is
  59.             updated_lines.append(line)
  60.  
  61.     # Create a new file name with "_edit" appended
  62.     new_file_path = os.path.splitext(file_path)[0] + "_edit.ini"
  63.  
  64.     # Print file start
  65.     print(f"Processing {file_path}...")
  66.  
  67.     # Write the updated lines to the new file
  68.     with open(new_file_path, 'w') as f:
  69.         f.write("\n".join(updated_lines))
  70.  
  71.     # Print file write
  72.     print(f"Updated file saved as {new_file_path}\n")
  73.  
  74. # Get the directory of the script
  75. script_directory = os.path.dirname(os.path.abspath(__file__))
  76.  
  77. # Iterate through all files in the script directory
  78. for filename in os.listdir(script_directory):
  79.     if filename.endswith(".ini"):
  80.         file_path = os.path.join(script_directory, filename)
  81.         process_ini_file(file_path)
Advertisement
Add Comment
Please, Sign In to add comment