13 Ekim 2013 Pazar

Delete All Files (*.*) [C#]

Sponsorlu Bağlantılar
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 methodDirectory.Get­Files. Then delete all files from the list.

Delete all files

[C#]
using System.IO;

string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
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#]
Array.ForEach(Directory.GetFiles(@"c:\MyDir\"),
              delegate(string path) { File.Delete(path); });


Sponsorlu Bağlantılar

Hiç yorum yok:

Yorum Gönder