1

I want to read the file type of a file and transfer to another folder using python. Is there’s a code in python that can read file type like “.mp3, .psd, .pdf, etc”

Thank you.

  • Do you only care about the extension, or are you trying to identify the type of file regardless of the extension? – Stephen Newell May 25 '20 at 14:04
  • Im trying to identify the type of a file so that i can create a function that creates a folder with the file type name on it. – Miguel Radaza May 25 '20 at 14:08
  • 2
    Does this answer your question? [How to check type of files without extensions in python?](https://stackoverflow.com/questions/10937350/how-to-check-type-of-files-without-extensions-in-python) – Tomerikoo May 25 '20 at 14:18

1 Answers1

0

You might want to check what is called "magic". Take a look at python libraries that deal with it like

https://pypi.org/project/python-magic/

In Unix (like) environments (linux, BSD, MacOs) you can use it as a command too, try file <file_name>: https://linux.die.net/man/5/magic

Yak O'Poe
  • 760
  • 4
  • 14
  • You are welcome, let us know which solution you decided to use. It might be useful for people who have the same problem as you. – Yak O'Poe May 25 '20 at 14:15