• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Changing all bitmap resources path at once . ChatGPT suggestion.

Enthusiast ,
Dec 09, 2023 Dec 09, 2023

Copy link to clipboard


Chat GPT wrote me a pyton script  that should replace  all bitmap resources to other folder .


here it is:

import xml.etree.ElementTree as ET
import os

def replace_bitmap_paths(sbs_file_path, old_path, new_path):
    # Parse the XML file
    tree = ET.parse(sbs_file_path)
    root = tree.getroot()

    # Find all elements with the 'bitmap' tag
    for bitmap_element in root.iter('bitmap'):
        # Get the current bitmap path
        current_path = bitmap_element.text

        # Check if the current path contains the old path
        if old_path in current_path:
            # Replace the old path with the new path
            new_bitmap_path = os.path.relpath(current_path, old_path)
            bitmap_element.text = os.path.join(new_path, new_bitmap_path)

    # Save the modified XML back to the file

# Example usage:
sbs_file_path = 'path/to/your/file.sbs'
old_path = 'textures/'
new_path = 'new/path/to/bitmaps/'

replace_bitmap_paths(sbs_file_path, old_path, new_path)


But it does nothing when I replace the path  to actiual one in the end of the script . The paths  stay same  in my sbs .


Could sombody  inspect the script and tell whats wrong  please.

Idea No status
Substance Graph






Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation