471,582 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,582 software developers and data experts.

find whether a folder has read/write permission?

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
2 5570
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
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.

Similar topics

reply views Thread by Samuel Shum | last post: by
2 posts views Thread by Urs Eichmann | last post: by
1 post views Thread by Alessandro Zucchi | last post: by
4 posts views Thread by Santaji | last post: by
reply views Thread by Ashraf Moollan www.ssw.com.au | last post: by
reply views Thread by Sanja Tanasijevic | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
1 post views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.