Saturday, January 10, 2015

Delete Files & Folders

Sample code to delete the Files and the Directories.

Namespace :


using System.IO;


Code:


Delete Directory:
         
            Directory.Delete("C:\test\")

            If Directory have the sub directories then,


            Directory.Delete("C:\test\", True)


Delete Files:


           File.Delete("C:\test\text.txt")


           To delete multiple files from Directory,


           string[] Files= Directory.GetFiles(@"c:\test\");


           foreach (string filePath in Files)
                  File.Delete(filePath);

No comments:

Post a Comment