DEV Community

Basha
Basha

Posted on

How to get the type of a file or folder in python

Hey:)
It is very easy to get the file type using os
you can get it by the following code snippet

import os
if os.path.isdir(file_dr):
   file = "folder"
else:
   file_ = name.split(".")
   file = repr(file_[-1])
print(file")
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay