Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- def process_ini_file(file_path):
- # Skip files with "_edit" in the file name
- if "_edit" in file_path:
- print('Skipping ' + file_path + " because its _edit suffix.")
- return
- # Read the content of the ini file
- with open(file_path, 'r') as f:
- lines = f.readlines()
- # Initialize a list to store updated lines
- updated_lines = []
- # Initialize variables to store the last two lines
- prev_line = None
- current_line = None
- # Iterate through each line
- for i in range(len(lines)):
- line = lines[i].strip()
- # Store the current line as the previous line
- prev_line = current_line
- current_line = line
- # Check if the line starts with "Outfit"
- if line.startswith("Outfit"):
- # Prompt the user for input
- user_input = input(f"Enter a new value for {current_line} (type 'stop' to finish): ")
- # Check if the user wants to stop
- if user_input.lower() == "stop":
- break
- # Split the line by "|"
- parts = current_line.split("|")
- # Update the line
- parts[4] = user_input
- # Join the parts back together
- updated_line = "|".join(parts)
- # Append updated line to the list
- updated_lines.append(updated_line)
- else:
- # Print the comment line in the console
- if line.startswith(";"):
- print(f"Comment: {line[1:]}")
- print("""
- OneHanded : 0
- TwoHanded : 1
- Marksman : 2
- Block : 3
- Smithing : 4
- HeavyArmor : 5
- LightArmor : 6
- Pickpocket : 7
- Lockpicking : 8
- Sneak : 9
- Alchemy : 10
- Specchcraft : 11
- Alteration : 12
- Conjuration : 13
- Destruction : 14
- Illusion : 15
- Restoration : 16
- Enchanting : 17
- """)
- # Append other lines as is
- updated_lines.append(line)
- # Create a new file name with "_edit" appended
- new_file_path = os.path.splitext(file_path)[0] + "_edit.ini"
- # Print file start
- print(f"============================== Processing {file_path}...")
- # Write the updated lines to the new file
- with open(new_file_path, 'w') as f:
- f.write("\n".join(updated_lines))
- # Print file write
- print(f"============================== Updated file saved as {new_file_path}\n")
- # Get the directory of the script
- script_directory = os.path.dirname(os.path.abspath(__file__))
- # Iterate through all files in the script directory
- for filename in os.listdir(script_directory):
- if filename.endswith(".ini"):
- file_path = os.path.join(script_directory, filename)
- process_ini_file(file_path)
Advertisement
Add Comment
Please, Sign In to add comment