Clean Directory - CSharp File IO

CSharp examples for File IO:Directory

Description

Clean Directory

Demo Code


using System.IO;/*from  ww w. ja v  a2s  .  c o  m*/
using System.Web;
using System.Linq;
using System.Collections.Generic;
using System;

public class Main{
        /**
         *  Clean up a given directory.
         *  @param directory The directory to clean.
         */
        public static void CleanDirectory(string directory)
        {
            try
            {
                string[] tempFiles = Directory.GetFiles(directory);

                // Delete each file in the given directory.
                foreach (string tempFile in tempFiles)
                {
                    File.Delete(tempFile);
                }
            }
            catch (Exception ex)
            {
                // TODO: Add handling code here.
            }
        }
}

Related Tutorials