0

Is there any way to retrieve a file type name in Python using the OS module?

An example made up command:

>>> os.file_type('txt')

Would return:

'Text Document'

Any help would be appreciated :)

Oscar.

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
Oscar Peace
  • 99
  • 1
  • 2
  • 11

1 Answers1

0

For getting file type you need to check the extension of the file

I think this can help.

import os

if os.path.splitext(file)[1] == ".txt":
    pritn 'Text Document'

For os related task you can look over this doc.

https://github.com/Projesh07/Python-basic/blob/master/python_os_module/python_os_module.py

Projesh Bhoumik
  • 1,058
  • 14
  • 17