Click here to Skip to main content
13,043,092 members (58,791 online)
Click here to Skip to main content
Add your own
alternative version


26 bookmarked
Posted 22 Jan 2001

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

    You may also be interested in...


    Comments and Discussions

    QuestionWhy reinvent the wheel? Pin
    Eric Van Wieren23-Oct-07 8:51
    memberEric Van Wieren23-Oct-07 8:51 
    Questionshankar Narayan Where are you ? Pin
    Software_Specialist4-Jun-07 3:03
    memberSoftware_Specialist4-Jun-07 3:03 
    GeneralDeleting files on WIN98 SE Pin
    Jaysen Naicker1-Dec-03 20:09
    sussJaysen Naicker1-Dec-03 20:09 
    Questionwhat is winforms Pin
    sakuragi10-Oct-03 14:47
    membersakuragi10-Oct-03 14:47 
    GeneralCompile Pin
    HTempelman8-Jul-03 10:25
    memberHTempelman8-Jul-03 10:25 
    GeneralA Simpler Solution Pin
    Anonymous17-May-03 17:34
    sussAnonymous17-May-03 17:34 
    GeneralRe: A Simpler Solution Pin
    mcaouette30-Apr-04 4:34
    membermcaouette30-Apr-04 4:34 

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

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

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