Advertisement
Landerin

Sims 3 Deep Clean Python Script

Mar 13th, 2025 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.30 KB | Gaming | 0 0
  1. import os
  2. import shutil
  3. import glob
  4. import platform
  5.  
  6. def clean_sims3_cache():
  7.     """
  8.    Cleans various cache files and folders for The Sims 3 to help resolve
  9.    performance issues and other problems.  This script should be placed in
  10.    'Documents\\Electronic Arts\\The Sims 3' folder.
  11.    """
  12.  
  13.     if os.path.exists("DeviceConfig.log"):
  14.         # Delete specific files
  15.         files_to_delete = [
  16.             "CASPartCache.package",
  17.             "compositorCache.package",
  18.             "scriptCache.package",
  19.             "simCompositorCache.package",
  20.             "socialCache.package",
  21.             os.path.join("DCCache", "dcdb0.dbc"),
  22.             os.path.join("DCCache", "missingdeps.idx"),
  23.         ]
  24.  
  25.         for file_path in files_to_delete:
  26.             try:
  27.                 if os.path.exists(file_path):
  28.                     os.remove(file_path)
  29.                     print(f"Deleted: {file_path}")
  30.             except Exception as e:
  31.                 print(f"Error deleting {file_path}: {e}")
  32.  
  33.         # Delete files in Downloads, SigsCache, and Thumbnails folders
  34.         folders_with_patterns = {
  35.             "Downloads": "*.bin",
  36.             "SigsCache": "*.bin",
  37.             "Thumbnails": "*.package",
  38.         }
  39.  
  40.         for folder, pattern in folders_with_patterns.items():
  41.             full_pattern = os.path.join(folder, pattern)
  42.             for file_path in glob.glob(full_pattern):
  43.                 try:
  44.                     os.remove(file_path)
  45.                     print(f"Deleted: {file_path}")
  46.                 except Exception as e:
  47.                     print(f"Error deleting {file_path}: {e}")
  48.  
  49.         # Handle FeaturedItems folder
  50.         featured_items_path = "FeaturedItems"
  51.         if os.path.exists(featured_items_path):
  52.             try:
  53.                 # Delete all files in FeaturedItems
  54.                 for file_path in glob.glob(os.path.join(featured_items_path, "*")):
  55.                     os.remove(file_path)
  56.                     print(f"Deleted: {file_path}")
  57.  
  58.                 # Remove the FeaturedItems directory
  59.                 os.rmdir(featured_items_path)
  60.                 print(f"Removed directory: {featured_items_path}")
  61.  
  62.                 # Recreate FeaturedItems as an empty file
  63.                 with open(featured_items_path, "w") as f:
  64.                     pass
  65.                 print(f"Recreated {featured_items_path} as an empty file.")
  66.             except Exception as e:
  67.                 print(f"Error handling {featured_items_path}: {e}")
  68.  
  69.         # Delete files in DCBackup, except ccmerged.package
  70.         dc_backup_path = "DCBackup"
  71.         for file_path in glob.glob(os.path.join(dc_backup_path, "*")):
  72.             if os.path.basename(file_path).lower() != "ccmerged.package":
  73.                 try:
  74.                     os.remove(file_path)
  75.                     print(f"Deleted: {file_path}")
  76.                 except Exception as e:
  77.                     print(f"Error deleting {file_path}: {e}")
  78.  
  79.         # Delete xcpt*, ScriptError_*, and KW* files in the current directory
  80.         for pattern in ["xcpt*", "ScriptError_*", "KW*"]:
  81.             for file_path in glob.glob(pattern):
  82.                 try:
  83.                     os.remove(file_path)
  84.                     print(f"Deleted: {file_path}")
  85.                 except Exception as e:
  86.                     print(f"Error deleting {file_path}: {e}")
  87.  
  88.         # Delete files in WorldCaches folder, only on Windows
  89.         if platform.system() == "Windows":
  90.             world_caches_path = "WorldCaches"
  91.             world_caches_pattern = os.path.join(world_caches_path, "*")
  92.             for file_path in glob.glob(world_caches_pattern):
  93.                 try:
  94.                     os.remove(file_path)
  95.                     print(f"Deleted: {file_path}")
  96.                 except Exception as e:
  97.                     print(f"Error deleting {file_path}: {e}")
  98.         else:
  99.             print("Skipping WorldCaches cleanup.  This is only done on Windows.")
  100.  
  101.         print("Cache cleaning complete.")
  102.  
  103.     else:
  104.         print(
  105.             "This file does not appear to be in the correct directory! "
  106.             "Please place this file in your 'Documents\\Electronic Arts\\The Sims 3' folder."
  107.         )
  108.         input("Press Enter to exit.")  # Equivalent of 'pause' in batch
  109.  
  110. if __name__ == "__main__":
  111.     clean_sims3_cache()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement