import os import sys # Change tms tiles to xyz tiles directory = os.path.dirname(os.path.realpath(sys.argv[0])) #get the directory of your script for subdir, dirs, files in os.walk(directory): for filename in files: if filename.find('.png') > 0: subdirectoryPath = os.path.relpath(subdir, directory) #get the path to your subdirectory filePath = os.path.join(subdirectoryPath, filename) #get the path to your file z, x, y = filePath.split('/') y = y[:-4] z, x, y = int(z), int(x), int(y) newy = 2**z - y - 1 newFilePath = os.path.join(directory, str(z), str(x), str(newy)+'.png') print("Changing", os.path.join(subdir, filename), "to", newFilePath) os.rename(os.path.join(subdir, filename), newFilePath)