how to delete files in folder and subfolders in C# | Coding Cluster - using asp.net, c#, mvc 4, iphone, php, ios, javascript, in asp.net mvc 3 & more
 

how to delete files in folder and subfolders in C#

Tuesday

c# - how to delete all files and folders in a directory?:
This examples shows how to delete all files (*.*) from a folder in C#.
First, you need to get the list of file names from the specified directory (using static method Directory.Get­Files. Then delete all files from the list.
Delete all files
C# code
using System.IO;
string[] filePaths = Directory.GetFiles(@"d:\Images\");
foreach (string filePath in filePaths)
  File.Delete(filePath);

Delete all files (one-row example)
To delete all files using one code line, you can use Array.ForEach with combination of anonymous method.
C# code
Array.ForEach(Directory.GetFiles(@"d:\Images\"),
              delegate(string path) { File.Delete(path); });
Share this post, if it is useful to you. Thanks!.

0 comments:

Post a Comment

Share your thoughts here...

 
 
 

RECENT POSTS

Boost

 
Blogger Widgets