/// <summary> /// Removes all the content of a directory but not the directory itself /// </summary> /// <param name="LOCATION">The directory of which you want to remove the contents</param> public void RemoveAll(string LOCATION) { string DIR = LOCATION; if (DIR.Length == 1) { DIR += @":\"; } else if (!DIR.EndsWith(@"\")) { DIR += @"\"; } try { System.IO.DirectoryInfo DI = new System.IO.DirectoryInfo(DIR); foreach (System.IO.FileInfo f in DI.GetFiles()) { try { f.Delete(); } catch { } } foreach (System.IO.DirectoryInfo d in DI.GetDirectories()) { try { d.Delete(true); } catch { } } } catch { } } |