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 Chance 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 last number (assuming it's the last part)
- try:
- parts[-1] = str(int(user_input)) # Convert user input to an integer
- except ValueError:
- print("Invalid input. Please enter a valid number.")
- continue
- # 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:]}")
- # 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