By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,725 Members | 1,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,725 IT Pros & Developers. It's quick & easy.

find whether a folder has read/write permission?

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Take a look at the FileIOPermission class.

Also, if you need some examples in C++, you might need to try another group.

"Chen Zhuo" <ch*********@hotmail.com> wrote in message
news:es**************@TK2MSFTNGP12.phx.gbl...
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

Nov 17 '05 #2

P: n/a
Thanks.. but still not sure how to get the current user's permission of
the specified folder? Could you give me some code segment?
Thanks ya

Btw, seems that GetDirectories() is too powerful... even I set C:\test
to be non-access to anyone, this API still can get the sub directories
under it!...
Peter Rilling wrote:
Take a look at the FileIOPermission class.

Also, if you need some examples in C++, you might need to try another group.

"Chen Zhuo" <ch*********@hotmail.com> wrote in message
news:es**************@TK2MSFTNGP12.phx.gbl...
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


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.