Hi,
I need to write some code to test whether a folder has read/write
permission. The idea is to try to read sub-directories in this folder,
if succeed, then test whether it's read-only. Any exception thrown means
we don't have permission to access this folder:
bool IsDirectoryAccessible(string path)
{
try
{
bool retVal = false;
System::IO::DirectoryInfo* dirInfo = new
System::IO::DirectoryInfo(Marshal::ToString(path)) ;
dirInfo->GetDirectories();
// GetDirectories() throw Exception if the folder is not accessible
if(IsReadOnly(path))
retVal = true;
return retVal;
}
catch (System::Exception* ex)
{
Util::Managed::Rethrow(ex);
}
}
But I think this algorithm is not so straight-forward. Anyone have
better idea of testing the folder accessibility?
Thanks a lot