I have a number of image files stored as 0.png, 1.png, ..., x.png in a folder. I have to rename then in the opposite order, i.e. 0->x, 1->(x-1), .., (x-1)->1, x->0. I have written the following code in python.
for filename in os.listdir("."):
tempname = "t" + filename
os.rename(filename, tempname)
for x in range(minx, maxx+1):
tempname = "t" + str(x) + ".png"
newname = str(maxx-x) + ".png"
os.rename(tempname, newname)
I encounter the following error:
OSError: [Errno 2] No such file or directory
What am I doing wrong? Is there a smarter way of doing this?