/// <summary>
/// Gets a list of the contents of a directory at the specified path.
/// </summary>
/// <param name="path">The path of the directory to get a list of the contents of.</param>
/// <param name="getSubDirs">Whether to obtain a list of the contents of all subdirectories as well.</param>
/// <returns>An array of strings with the names of directories and files under the supplied path.
/// Null if the path is invalid, does not exist, or the current process does not have permission
/// to get the directory listing.</returns>
static public string[] GetListing(string path, bool getSubDirs)
{
// Check whether the path supplied is valid.
if (!string.IsNullOrEmpty(path))
{
// Check whether the path for the directory exits.
if (SystemDirectory.Exists(path))
{
// The directory exists.
// Check if we need to get subdirectory content as well.
if (!getSubDirs)
{
// We don't need to get subdirectory content.
try
{
return(SystemDirectory.GetFileSystemEntries(path));
}
catch (UnauthorizedAccessException)
{
// We don't have the required permission.
return(null);
}
}
else
{
// We need to get subdirectory content as well.
return(SystemDirectory.GetFileSystemEntries(path, "*", SearchOption.AllDirectories));
}
}
}
// The path is not valid.
return(null);
}