c# - delete folder/files and subfolder -
i want delete folder containing files , subfolder, containing files. have used everything, not working me. i'm using following function in web-application asp.net:
var dir = new directoryinfo(folder_path); dir.delete(true);
sometimes deletes folder, or doesn't. if subfolder contains file, deletes file, , not folder well.
this looks right: http://www.ceveni.com/2008/03/delete-files-in-folder-and-subfolders.html
//to call below method emptyfolder(new directoryinfo(@"c:\your path")) using system.io; // dont forget use header //method delete files in folder , subfolders private void emptyfolder(directoryinfo directoryinfo) { foreach (fileinfo file in directoryinfo.getfiles()) { file.delete(); } foreach (directoryinfo subfolder in directoryinfo.getdirectories()) { emptyfolder(subfolder); } }
Comments
Post a Comment