I want to loop through hundreds of file names and rename them. The issue is that the file names are over 260 characters and contain characters that make os.rename not usable.
The code below runs with regular filenames but not with the files described earlier:
import os
filepath = "path"
path = os.chdir(filepath)
count = 1
for filename in os.listdir(path):
new_file_name = f"{count}.csv"
os.rename(filename,new_file_name)
count += 1
When I run with the long file names, I get:
Traceback (most recent call last):
File "C:\Users\sarah\Desktop\Python\program.py", line 7, in <module>
os.rename(filename,new_file_name)
FileNotFoundError: [WinError 3] The system cannot find the path specified:
Is there a way of looping through these file names and renaming them?