.Net Framework does not have a function that can delete all contents of a folder, eg. if you try DirectoryInfo.Delete(true); and the hierachy have any content, then it will fail with "Directory is not empty". This means we have to write a recursive delete function each time we want to clear a directory hierarchy.
References :
string sessionsPath = Server.MapPath("~/_menulab/Discussions/Sessions"); if (System.IO.Directory.Exists(sessionsPath)) { ClearFolder(sessionsPath); }
public static void ClearFolder(string pFolderPath) { DirectoryInfo dirInfo = new DirectoryInfo(pFolderPath); FileInfo[] fileInfos = dirInfo.GetFiles(); foreach (FileInfo fileInfo in fileInfos) { if (!fileInfo.IsReadOnly) { fileInfo.Delete(); } } DirectoryInfo[] subDirInfos = dirInfo.GetDirectories(); foreach (DirectoryInfo subDirInfo in subDirInfos) { ClearFolder(subDirInfo.FullName); subDirInfo.Delete(); } }
If you have a computer, you are managing links
Manylink allows you to :