in SimpleDUTRemote/HelperFunctions/ReadWriteChecks.cs [18:51]
internal static bool CheckReadFromFileOrDir(string path)
{
try
{
// handle glob expressions - if we see wildcards, just grab the parent directory
if (path.Contains("*") || path.Contains("?"))
{
path = Path.GetDirectoryName(path);
}
if (IsDir(path))
{
// try to list contents, will throw if does not exist
var tmp = Directory.GetFileSystemEntries(path);
// if this didn't throw, we assume we're safe.
return true;
}
else
{
// this is a file, can we open it for reading?
using (var fstream = File.Open(path, FileMode.Open))
{
// if we're here, we can open the file without issue.
return true;
}
}
}
catch (IOException)
{
return false;
}
}