Reputation: 19
Having trouble shortening to the first 13 characters of a file name, any suggestions?
import os
path = '/home/ben/Desktop/UK_DDV'
files = os.listdir(path)
for file in files:
outfile = file[:13]
os.rename(os.path.join(path, outfile), os.path.join(path, outfile)+'.tif')
Keeping getting the error
'FileNotFoundError: [Errno 2] No such file or directory:'
Upvotes: 0
Views: 68
Reputation: 406
The first parameter to os.rename()
should be using the original filename, file
instead of outfile
.
Upvotes: 2