I am processing a TreeView of directories and files, users can select either a file, or a directory and then do something with it. This requires me to have a method which performs different actions if they have selected a file, or a directory.
At the moment I am doing something like this to determine if the path is a file or a directory:
bool bIsFile = false;
bool bIsDirectory = false;
try
{
string[] subfolders = Directory.GetDirectories(strFilePath);
bIsDirectory = true;
bIsFile = false;
}
catch(System.IO.IOException)
{
bIsFolder = false;
bIsFile = true;
}
I cannot help to feel that there is a better way to do this! But I cannot find any .Net methods which I can ask "Is this path a directory or a file ?".
Any suggestions ?
Thanks!