I was making a script that renames files in a given directory into "CoronaVirus" and when testing it I noticed that it only does it in the given directory and not in it's subfolders. The code looks something like this(note: this one works):
import os
PRF = input("Input Directory: ")
def main():
for file in PRF:
for filename in os.listdir(PRF):
i = 0
dst = "CoronaVirus" + str(i)
src = PRF + filename
dst = PRF + dst
os.rename(src , dst)
i += 1
if __name__ == "__main__"":
main()
After I saw that it only goes through the given directory I tried adding a new statement(forgive me if that's not what it is called) called subdir thinking that it would make it look throuh folders. That made the code look like this:
import os
PRF = input("Input Directory: ")
def main():
for subdir , file in PRF:
for filename in os.listdir(PRF):
i = 0
dst = "CoronaVirus" + str(i)
src = PRF + filename
dst = PRF + dst
os.rename(src , dst)
i += 1
if __name__ == "__main__"":
main()
But this doesn't seem to work as it gives this error:
Traceback (most recent call last):
File "C:/Users/Acer/Desktop/Python/Pyinstaller/OSM.py", line 17, in <module>
main()
File "C:/Users/Acer/Desktop/Python/Pyinstaller/OSM.py", line 7, in main
for subdir , file in PRF:
ValueError: not enough values to unpack (expected 2, got 1)
Can somebody explain why this is happening? I'm a beginner and would like to avoid this issue in the future. Thanks!