Home > Uncategorized > Enumerate all files in a directory, recursively

Enumerate all files in a directory, recursively

        public void ReadDirectory (string TargetDirectory, bool RecursivePlz, string LogFilename)
        {
            TargetDirectory = TargetDirectory.ToLower();

            //exclude dfsrprivate folders
            if (!TargetDirectory.Contains("dfsrprivate"))
            {

                //find the directory
                if (Directory.Exists(TargetDirectory))
                {
                    //find the files in this directory
                    string[] FileList = Directory.GetFiles(TargetDirectory);

                    //check files in this directory
                    foreach (string ffile in FileList)
                    {

                        FileInfo finfo = new FileInfo(ffile);
                        if (finfo.Exists)
                        {
                            //get the full file size
                            int SizeOfFile = Int32.Parse(finfo.Length.ToString());
                        }
                    }

                    //find all the sub-directories in the directory
                    string[] SubDirectorylist = Directory.GetDirectories(TargetDirectory);

                    //reverse the entire list
                    Array.Reverse(SubDirectorylist);

                    //if user has requested recursive action, go ahead...
                    if (RecursivePlz == true)
                    {
                        if (Directory.Exists(TargetDirectory))
                        {
                            //trigger ReadFiles() on these as well
                            foreach (string ddir in SubDirectorylist)
                            {
                                ReadFiles(ddir, RecursivePlz, LogFilename, SizePerRead, SizePerReadOp, FlushToLogSeconds);
                            }
                        }
                    }
                }
            }

        }
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: