I started programming in Python a couple of days ago and I have a problem I couldn’t solve yet.
I want to correct a files file extension by guessing its mimetype.
I tried this:
new_file_name = mimetypes.guess_extension(mimetypes.guess_type(file_name)))
os.rename(file_name, new_file_name)
Why doesnt it work?
mimetypesuses the existing extension to guess the file type. Usemagicinstead to examine the contents.