Delete File or Folder path in C#

Delete File or Folder path in C#
By 42Gears Team
void DeletePath(string path) { try { FileInfo finfo = new FileInfo(path); if (finfo.Attributes == FileAttributes.Directory) { //recursively delete directory Directory.Delete(path, true); } else if(finfo.Attributes == FileAttributes.Normal) { File.Delete(path); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
To learn more about our products, please visit https://www.42gears.com.

“Written with expertise and passion to help you understand the topic better.”

4
42Gears Team – Content Author
Published on: October 31, 2010

Subscribe to our newsletter

Stay updated with the latest news, articles, and resources on enterprise mobility.

Weekly articles
Actionable insights delivered once a week. No noise.
No spam
Your privacy matters. Unsubscribe anytime.