Click here to Skip to main content
Click here to Skip to main content

CleanUp Files using C Sharp

, 22 Jan 2001
Rate this:
Please Sign up or sign in to vote.
Describes the File Access, Persistance with C Sharp
  • Download source files - 35 Kb
  • Introduction

    This article is just a sample application which uses the .Net framework to delete unwanted files from the directories specified. The Sample uses the System.IO to manage the task and uses a recursive function to delete files.

    private void RemoveFiles(string strPath)
        Directory dTemp = new Directory(strPath);
        for(int i = 0; i < lstExts.Items.Count; i++)
            string s = lstExts.Items[i].ToString();
            File[] fileList = dTemp.GetFiles(lstExts.Items[i].ToString());
            for(int j = 0; j < fileList.Length; j++)
                    catch(SecurityException e)
                        lblStatus.Text = e.Message;
                    catch(Exception ex)
                        lblStatus.Text = ex.Message;
    private void EmptyDirectory(string strPath)
        Directory dirFinder = new Directory(strPath);
        Directory[] dirList = dirFinder.GetDirectories();    
        for(int i = 0; i < dirList.Length; i++)
            string strTemp = strPath + "\\" + dirList[i].Name;

    The two functions provides the capability of deleting of files recursively. The Classes used in this Project

    • Form
    • File
    • Directory
    • Button
    • ListBox
    • TextBox


    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    About the Author

    Shankara Narayanan

    United States United States
    No Biography provided

    Comments and Discussions

    QuestionWhy reinvent the wheel? PinmemberEric Van Wieren23-Oct-07 9:51 
    Questionshankar Narayan Where are you ? PinmemberSoftware_Specialist4-Jun-07 4:03 
    GeneralDeleting files on WIN98 SE PinsussJaysen Naicker1-Dec-03 21:09 
    Questionwhat is winforms Pinmembersakuragi10-Oct-03 15:47 
    GeneralCompile PinmemberHTempelman8-Jul-03 11:25 
    GeneralA Simpler Solution PinsussAnonymous17-May-03 18:34 
    GeneralRe: A Simpler Solution Pinmembermcaouette30-Apr-04 5:34 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Terms of Use | Mobile
    Web04 | 2.8.150327.1 | Last Updated 23 Jan 2001
    Article Copyright 2001 by Shankara Narayanan
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid