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:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...