[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C# delete read-only directory

Posted on 2007-08-01
2
Medium Priority
?
7,136 Views
Last Modified: 2013-12-17
How do I delete a read-only directory (other than executing attrib)? Is there a way to change the attributes on directories, like there is for files?

Thanks
0
Comment
Question by:gromul
2 Comments
 
LVL 8

Expert Comment

by:sabeesh
ID: 19614130
FileInfo fi = new FileInfo("");
        fi.Attributes = FileAttributes.Archive;


you can set attribute and make it deletable
0
 
LVL 21

Accepted Solution

by:
Yurich earned 2000 total points
ID: 19614289
I tried the one above and it didn't let me do it... It will work with some correction:

      DirectoryInfo dir = new DirectoryInfo( @"C:\Deleteme\" );
      dir.Attributes = FileAttributes.Normal;
      dir.Delete( true );  // delete recursively


Moreover, this code will work only if you have directory readonly but all contents normal. Otherwise, you have to iterate through your directory and set all files and folders to Normal (clearing ReadMe) as when you do this:
   dir.Attributes = FileAttributes.Normal;
it sets it only for your current directory.

Cheers,
Yurich
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question