I have a folder full of files and they don't have an extension. How can I check file types? I want to check the file type and change the filename accordingly. Let's assume a function filetype(x)
returns a file type like png
. I want to do this:
files = os.listdir(".")
for f in files:
os.rename(f, f+filetype(f))
How do I do this?
file types
. Do you mean determining if it's a gif, png, bmp or jpg? Do you just want to know if it's text/binary? Executable? – Meneauapplication/jpeg
returns.jpe
rather than the preferred.jpg
. It really does appear to be guessing. – Volatilejpe
is just happens to be the first match for image/jpeg, tryguess_all_extensions
to see them all. – Neurosis