I am working on determining if a removable drive is read-only using C# (.NET 4.0). I've read many articles that detail the process for determining if a directory is read-only using the following code that came from this page:
var di = new DirectoryInfo(folderName);
if(di.Exists)
{
if (di.Attributes.HasFlag(FileAttributes.ReadOnly))
{
//IsReadOnly...
}
}
However, I've tried this method using the root directory, and even though the entire drive is read-only (I'm using an SD Card that is locked), I never make it to the line //IsReadOnly...
. The contents of the drive cannot be guaranteed (it could be empty or have many, many files), so testing any sub-directory is out of the question. I know an easy test would be to write a small file to the drive and catch any exceptions, but I would prefer a different method.
Does anyone know of a good solution to this problem?