c# check if path a Directory or File [solved]

G’Day Fellas,

I had this problem where I had to check whether the supplied path is a Path to File or it is a Directory.

There are few ways of doing this. e.g. using

  • File.Exists()
  • Directory.Exists()



But then I thought there would definitely something else that could improve the code. There is nothing wrong with the above approach but I then found out that File Class comes with a method called GetAttributes

Here is how we use it

[geshi lang=”csharp” nums=”1″ target=”_self” ]


You can put it in any of your Util class function to re-use above code.

I hope this helps

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.