How recursively delete a directory files in C#,that has Permission problem

by daz 10/29/2009 6:48:00 PM

It is sometime difficulte to delete folder or directory in your machine with applications. 

This is one of the easiest way. to resset the files permissions before deleting them.

public static bool DeleteFolder(string  dir)

{

   bool result = false;

   string[] files = Directory.GetFiles(dir);

   string[] directory = Directory.GetDirectories(dir);

foreach (string file in files)

     File.SetAttributes(file, FileAttributes.Normal);

     File.Delete(file);

foreach (string st in  directory)

{

  DeleteDirectory(st);

    Directory.Delete(dir, false ); 

    return result;

} }}

 

Tags:

About the author

Name of author
DavidZ
.Net Programmer
E-mail me Send mail
WebHosting Canada USA

Partners

Repertoire canada

Recent comments

Archive

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2012

Sign in