Click here to Skip to main content
15,894,539 members
Articles / Desktop Programming / WPF

WPF Version of IPMessager

Rate me:
Please Sign up or sign in to vote.
4.87/5 (10 votes)
27 Feb 2010CPOL2 min read 44.1K   2.7K   55  
Redeveloped the IPMessager program using C# and WPF
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace QiHe.CodeLib
{
    public class DirectoryWalker
    {
        public string SearchPattern = "*";

        public delegate void OnVisitDirectory(DirectoryInfo dirInfo);

        public delegate void OnVisitFile(FileInfo fileInfo);

        public OnVisitDirectory BeforeVisitDirectory;

        public OnVisitDirectory AfterVisitDirectory;

        public OnVisitFile VisitFile;

        public void Traverse(string path)
        {
            DirectoryInfo dirInfo = new DirectoryInfo(path);
            VisitDirectoryInfo(dirInfo);
        }

        protected void VisitDirectoryInfo(DirectoryInfo dirInfo)
        {
            if (BeforeVisitDirectory != null)
            {
                BeforeVisitDirectory(dirInfo);
            }

            // Visit Files
            foreach (FileInfo fileInfo in dirInfo.GetFiles(SearchPattern, SearchOption.TopDirectoryOnly))
            {
                VisitFileInfo(fileInfo);
            }

            // Visit Sub Directories
            foreach (DirectoryInfo subDirInfo in dirInfo.GetDirectories())
            {
                VisitDirectoryInfo(subDirInfo);
            }

            if (AfterVisitDirectory != null)
            {
                AfterVisitDirectory(dirInfo);
            }
        }

        protected void VisitFileInfo(FileInfo fileInfo)
        {
            if (VisitFile != null)
            {
                VisitFile(fileInfo);
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect YunCheDa Hangzhou
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions