Ren'Py Remove all unused images?

sembolan

Newbie
Jan 21, 2021
83
187
My game has a lot of images that I didn't end up using. It would be a major pain to go through all my code to delete the images one by one.

Does anyone have a good idea on how to remove all unused images in a game?

Or is there a setting to enable where if I try to delete all the images, I get a message of "image is in use" for the ones that are used in my code?

I'm using Visual Studio Code as my coding program.
 

HELIO CESAR

Member
May 30, 2018
326
691
You want to delete the images that you arent using in the game code right?

It really depends in how you structured your code to help yourself, supose all your renders are in a specific name struct or format, this would help a lot.
You could maybe write a lil python script that parses your code and saves the images names in a list and uses it to remove only the images that you want from the renders directory, something like this:

lets also supose that all images are being used like this: show render1.png with ...

Code:
codef = open("code.txt", "r")
lines = codef.readlines()
word = ".png"
renders_used = []

for line in lines:
    if word in line:
        image = line.split()
        renders_used.append(image[1])

renders_dir =  os.listdir(path_to_renders)
for item in renders_dir:
    if item not in renders_used:
        os.remove(os.path.join(path_to_renders, item))
Like said, this would try to save the names of the renders that were mentioned in the code in a list and check another list of all the rendered images to see if the current image in the loop was used, if not, it will be deleted.
just a idea, really depends in how you structured your code and renders.
Always remember to backup and test the code in steps. Good luck!
 
Last edited:
  • Like
Reactions: sembolan

sembolan

Newbie
Jan 21, 2021
83
187
You want to delete the images that you arent using in the game code right?

It really depends in how you structured your code to help yourself, supose all your renders are in a specific name struct or format, this would help a lot.
You could maybe write a lil python script that parses your code and saves the images names in a list and uses it to remove only the images that you want from the renders directory, something like this:

lets also supose that all images are being used like this: show render1.png with ...

Code:
codef = open("code.txt", "r")
lines = codef.readlines()
word = ".png"
renders_used = []

for line in lines:
    if word in line:
        image = line.split()
        renders_used.append(image[1])

renders_dir =  os.listdir(path_to_renders)
for item in renders_dir:
    if item not in renders_used:
        os.remove(os.path.join(path_to_renders, item))
Like said, this would try to save the names of the renders that were mentioned in the code in a list and check another list of all the rendered images to see if the current image in the loop was used, if not, it will be deleted.
just a idea, really depends in how you structured your code and renders.
Always remember to backup and test the code in steps. Good luck!
Thanks a lot! I'll try it out