Click here to Skip to main content
15,915,019 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to get the directory is readonly
string[] drives = Directory.GetLogicalDrives();
string s = drives.IsReadOnly.ToString();

but how can I avoid readonly drives and prevent that an exception is raised?
Posted
Updated 9-Nov-10 9:20am
v2

1 solution

Here some code that will give true if a directory is readonly, false otherwise.
C#
static void IsFileSystemItemReadOnly(FileSystemInfo fsi)
{
   return (fsi.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly;
}

 IsFileSystemItemReadOnly(new DirectoryInfo(@"C:\"));

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900