Skip to content

Instantly share code, notes, and snippets.

@Shaptic
Created July 13, 2012 19:46
Show Gist options
  • Save Shaptic/3106976 to your computer and use it in GitHub Desktop.
Save Shaptic/3106976 to your computer and use it in GitHub Desktop.
Find all map tile files
import os
# Finds all image files starting with
# Map_ and ending with the .png extension.
# Returns a list of all images.
def find_tiles(directory):
textures = []
for root, dirs, files in os.walk(directory):
for tmp_file in files:
if(tmp_file.startswith("Map_") and tmp_file.endswith(".png")):
textures.append(tmp_file)
print "Found %s in %s" % (tmp_file, root)
return textures
def main():
textures = find_tiles("Data/Images")
print "%d textures found!" %(len(textures))
if(len(textures) > 0):
texture_file = open("Data/Levels/ValidNames.dat", "w")
texture_file.write("// This list has been automatically generated by a script.\n")
for texture in textures:
texture_file.write("Data/Images/Map/%s\n" % (texture))
texture_file.close()
if(__name__ == "__main__"):
main()
raw_input("Press ENTER to exit.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment