Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete Files,MainFolder and SubFolders

Tags:

c#

.net

I am having a problem in deleting Files,MainFolder And SubFolders in a Directory. I want to delete all the Files,MainFolders and Subfolders after the work is finish . I am using this following code.

        private void bgAtoZ_DoWork(object sender, DoWorkEventArgs e)
        {
           string Path1 = (string)(Application.StartupPath + "\\TEMP\\a-z\\test" + "\\" +name);
           StreamReader reader1 = File.OpenText(Path1);
           string str = reader1.ReadToEnd();
           reader1.Close();
           reader1.Dispose();
           File.Delete(Path1);
         }

If anyone Would help me it would be nice for me. Thanks In Advance

like image 969
G Arshiya Avatar asked Dec 01 '22 08:12

G Arshiya


2 Answers

Direcory.Delete(path, true);

See here

like image 200
Emond Avatar answered Dec 02 '22 21:12

Emond


I'd go for a:

Directory.Delete(Path1, true)

that will delete folders and files contained.

like image 30
Andrea Pigazzini Avatar answered Dec 02 '22 20:12

Andrea Pigazzini