Function to check whether path is directory ( folder ) or not ( file or something else ) .

Code Snippet

using System.IO;

class FileManager
{
    public static bool IsDirectory(string path)
    {
        return File.GetAttributes(path).HasFlag(FileAttributes.Directory);
    }
}

Sample Usage

if (FileManager.IsDirectory(@"C:\NewFolder\SubNewFolder"))
{
// do something here;
}
else
{
// given path is not directory/folder;
}

Note

Make sure existence of given path otherwise it will throw the exception.


Categories : Programming, C#
Tags : Directory, Folder, File, IO, File Operation


author's photo

Author : Blue Cloud

Just a normal software developer who love to write code. Developing professional software since 1999. After working in the software industry for many years, I've started my own website to share knowledges and experiences.

COMMENTS
blog comments powered by Disqus