Guest User

abc2

a guest
Mar 19th, 2024
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.07 KB | None | 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 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 line
  42.             parts[4] = user_input
  43.  
  44.             # Join the parts back together
  45.             updated_line = "|".join(parts)
  46.  
  47.             # Append updated line to the list
  48.             updated_lines.append(updated_line)
  49.         else:
  50.             # Print the comment line in the console
  51.             if line.startswith(";"):
  52.                 print(f"Comment: {line[1:]}")
  53.                 print("""
  54.                    OneHanded : 0
  55.                    TwoHanded : 1
  56.                    Marksman : 2
  57.                    Block : 3
  58.                    Smithing : 4
  59.                    HeavyArmor : 5
  60.                    LightArmor : 6
  61.                    Pickpocket : 7
  62.                    Lockpicking : 8
  63.                    Sneak : 9
  64.                    Alchemy : 10
  65.                    Specchcraft : 11
  66.                    Alteration : 12
  67.                    Conjuration : 13
  68.                    Destruction : 14
  69.                    Illusion : 15
  70.                    Restoration : 16
  71.                    Enchanting : 17
  72.                """)
  73.  
  74.             # Append other lines as is
  75.             updated_lines.append(line)
  76.  
  77.     # Create a new file name with "_edit" appended
  78.     new_file_path = os.path.splitext(file_path)[0] + "_edit.ini"
  79.  
  80.     # Print file start
  81.     print(f"============================== Processing {file_path}...")
  82.  
  83.     # Write the updated lines to the new file
  84.     with open(new_file_path, 'w') as f:
  85.         f.write("\n".join(updated_lines))
  86.  
  87.     # Print file write
  88.     print(f"============================== Updated file saved as {new_file_path}\n")
  89.  
  90. # Get the directory of the script
  91. script_directory = os.path.dirname(os.path.abspath(__file__))
  92.  
  93. # Iterate through all files in the script directory
  94. for filename in os.listdir(script_directory):
  95.     if filename.endswith(".ini"):
  96.         file_path = os.path.join(script_directory, filename)
  97.         process_ini_file(file_path)
Advertisement
Add Comment
Please, Sign In to add comment