I'm trying to rename a directory in Python
, such hat the directory will be renamed to its first 8 characters of its original name.
This is what I did:
import os
path = '/home/directories'
for root, dirs, files in os.walk(path):
for directory in dirs:
new_name = directory[0:8]
os.rename(directory, new_name)
I however get the following error:
Traceback (most recent call last):
File "xyz.py", line 8, in <module>
os.rename(directory, new_name)
OSError: [Errno 2] No such file or directory
How can I solve this error?
Thanks.