Saturday, September 25, 2010

How to delete a folder or delete all files in a folder

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    string f = @"C:\FolderToDelete";
    string d = @"C:\FilesToDelete";
    this.DeleteFiles(new DirectoryInfo(f));
    this.DeleteFolder(new DirectoryInfo(d));
}
 
public void DeleteFiles(DirectoryInfo destination)
{
    foreach (FileInfo f in destination.GetFiles())
        File.Delete(f.FullName);
    foreach (DirectoryInfo c in destination.GetDirectories())
        this.DeleteFiles(c);
}
public void DeleteFolder(DirectoryInfo destination)
{
    foreach (FileInfo f in destination.GetFiles())
        File.Delete(f.FullName);
    foreach (DirectoryInfo c in destination.GetDirectories())
        this.DeleteFolder(c);
    Directory.Delete(destination.FullName);
}

No comments:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...