Easy Question, Delete all files in a path then recreate the path.

Hello,

Just an easy question for someone, not for me cause I don’t know why it doesn’t work, so if anyone could amend this please help:

 if (!Directory.Exists(path))
                {                  
                      Directory.CreateDirectory(path);
                }
                else {

                     var hi = Directory.GetFiles(path);

                    for (int i = 0; i < hi.Length; i++) {
                        File.Delete(hi*);*

}

Directory.Delete(path);
Directory.CreateDirectory(path);
}

Glad it’s working, however you could replace all of the above with:

if (Directory.Exists(path)) { Directory.Delete(path, true); }
Directory.CreateDirectory(path);

That overload of Directory.Delete will remove the folder and all of its contents. So, no need to iterate through the contents…

Sorry It does work LoL, Just had to go out then back into unity for it to update haha.

Brain fart!