Is folder
This is a little helper function to check whether a given path is a folder or a file.
/// <summary>
/// Returns true if the given file path is a folder.
/// </summary>
/// <param name="Path">File path</param>
/// <returns>True if a folder</returns>
public bool IsFolder(string path)
{
return ((File.GetAttributes(path) & FileAttributes.Directory) == FileAttributes.Directory);
}
//Example:
// Define a test path
string filePath = @"C:\Test Folder\";
if (IsFolder(filePath)){
MessageBox.Show("The given path is a folder.");
}
else {
MessageBox.Show("The given path is a file.");
}
Url: http://www.jonasjohn.de/snippets/csharp/is-folder.htm
Language: C# | User: ShareMySnippets | Created: Oct 16, 2013