.net - "Access to the system path is denied" when using 'System.IO.Directory.Delete' -


I am using System.IO.Directory.Delete and delete the system folder I am trying to get such errors as 'my music', 'my video' etc., but I'm getting errors like "access to system path" C: \ users \ jbloggs \ Saved Games 'Disapproved' Although I can remove these folders without any problems in the Explorer, I have full permission for these folders.

My code:

  Public static zero ClearAttributes (string currentDir) {if (Directory.Exists (currentDir)) {string [] subdirectories = directory. Gate Directories (Current Dear); Foreacha (string die in sub-diures) Cleatulates (DIR); String [] files = files = directory Gatefiles (current dior); File (string files in the file) .net property (file, file. Attributes); }}  

Usage:

  Try {ClearAttributes (FolderPath); System.IO.Directory.Delete ("C: \\ user \\ jbloggs \\ saved games \", true); } Hold (IOException east) {message Box.Show (ex.Message); }   

Yes, that folder has a "read only" attribute set Will:

  var dir = new DirectoryInfo (@ "c: \ temp \ test"); Dir.Attributes = dir.Attributes & amp; ~ FileAttributes.ReadOnly; Dir.Delete ();  

When you delete stuff, you should always pay attention to the file attributes. Be sure to stay clear from the system or the repercussions, whatever, and be careful to read only.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -