0
I made a simple program in Python that renames with a random number all the files in the folder in which the program file is. After some attempts and mistakes, I noticed in some examples of the internet that in the loop that did the "reading" of the files had a variable more than the loop that I had thought. Can anyone tell me the use of it?
In this case here is the variable x
import os, random
dirs = os.listdir(".")
for x, file in enumerate(dirs):
src = file
newName = str(random.randint(1, 1000000))
os.rename(src, newName)
But when I remove this variable...
import os, random
dirs = os.listdir(".")
for file in enumerate(dirs):
src = file
newName = str(random.randint(1, 1000000))
os.rename(src, newName)
... gives the following error:
TypeError: rename: src should be string, bytes or os.PathLike, not tuple