Advertisement
ernand

Untitled

Dec 16th, 2024
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | Software | 0 0
  1. import os
  2. import zipfile
  3.  
  4. # Define the path to the mods folder and the target file path
  5. mods_folder = r"C:\Users\***\AppData\Roaming\PrismLauncher\instances\1.21\.minecraft\mods"
  6. target_path = "data\\c\\tags\\item\\"
  7. target_file = "coal.json"
  8.  
  9. # List to store the names of .jar files containing the target file
  10. found_jar_files = []
  11.  
  12. # Iterate over all .jar files in the mods folder
  13. for root, dirs, files in os.walk(mods_folder):
  14.     for file in files:
  15.         if file.endswith(".jar"):
  16.             jar_path = os.path.join(root, file)
  17.            
  18.             try:
  19.                 # Open the .jar file as a zip archive
  20.                 with zipfile.ZipFile(jar_path, 'r') as jar:
  21.                     # Check if the target path and file exists in the .jar archive
  22.                     for entry in jar.namelist():
  23.                         # Check if the entry matches the target path and file
  24.                         if entry == f"{target_path}{target_file}":
  25.                             print(f"Found '{target_file}' in: {jar_path}")
  26.                             found_jar_files.append(jar_path)
  27.                             break  # Stop checking further entries in this .jar
  28.             except zipfile.BadZipFile:
  29.                 print(f"Error: {jar_path} is not a valid .jar file.")
  30.  
  31. # Print results
  32. if found_jar_files:
  33.     print(f"\nThe following .jar files contain '{target_file}':")
  34.     for jar_file in found_jar_files:
  35.         print(jar_file)
  36. else:
  37.     print(f"No '{target_file}' found in any .jar files in the folder: {mods_folder}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement