示例#1
0
        private void checkDirectories(String pathToCheck)
        {
            Console.WriteLine(String.Format("Checking path: {0}", pathToCheck));

            lvInvalidItems.Enabled = false;
            lvInvalidItems.Items.Clear();

            Cursor currentCursor = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;

            try
            {
                foreach (String dir in Directory.EnumerateDirectories(pathToCheck, "*", SearchOption.TopDirectoryOnly).Distinct())
                {
                    //Console.WriteLine(String.Format("Directory Entry: {0}", entry));
                    bool found = false;

                    foreach (String entry in Directory.EnumerateFileSystemEntries(dir, "*", SearchOption.TopDirectoryOnly).Distinct())
                    {
                        if (Directory.Exists(entry) && Path.GetFileName(entry).ToLower() == "extended")
                        {
                            // this directory is fine
                            Console.WriteLine(String.Format("Directory {0} is acceptable", entry));
                            found = true;
                        }
                        else
                        {
                            // this directory or file shouldn't be here
                            InvalidEntry invalid = new InvalidEntry();
                            invalid.fullPath      = entry;
                            invalid.invalidReason = "File/Directory should not be here";
                            String   type    = Directory.Exists(entry) ? "directory" : "file";
                            string[] reasons = { invalid.fullPath, invalid.invalidReason, };
                            lvInvalidItems.Items.Add(new ListViewItem(reasons, type));
                        }
                    }

                    if (!found)
                    {
                        InvalidEntry invalid = new InvalidEntry();
                        invalid.fullPath      = dir;
                        invalid.invalidReason = "Directory did not contain an Extended folder";
                        string[] reasons = { invalid.fullPath, invalid.invalidReason };
                        lvInvalidItems.Items.Add(new ListViewItem(reasons, "directory"));
                    }
                }
            }
            finally
            {
                lvInvalidItems.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                lvInvalidItems.Enabled = true;
                Cursor.Current         = currentCursor;
            }
        }
        private void checkDirectories(String pathToCheck)
        {
            Console.WriteLine(String.Format("Checking path: {0}", pathToCheck));

            lvInvalidItems.Enabled = false;
            lvInvalidItems.Items.Clear();

            Cursor currentCursor = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;

            try
            {

                foreach (String dir in Directory.EnumerateDirectories(pathToCheck, "*", SearchOption.TopDirectoryOnly).Distinct())
                {
                    //Console.WriteLine(String.Format("Directory Entry: {0}", entry));
                    bool found = false;

                    foreach (String entry in Directory.EnumerateFileSystemEntries(dir, "*", SearchOption.TopDirectoryOnly).Distinct())
                    {


                        if (Directory.Exists(entry) && Path.GetFileName(entry).ToLower() == "extended")
                        {
                            // this directory is fine
                            Console.WriteLine(String.Format("Directory {0} is acceptable", entry));
                            found = true;
                        }
                        else {
                            // this directory or file shouldn't be here
                            InvalidEntry invalid = new InvalidEntry();
                            invalid.fullPath = entry;
                            invalid.invalidReason = "File/Directory should not be here";
                            String type = Directory.Exists(entry) ? "directory" : "file";
                            string[] reasons = {invalid.fullPath, invalid.invalidReason, };
                            lvInvalidItems.Items.Add(new ListViewItem(reasons, type));
                        }

                    }

                        if (!found)
                        {
                            InvalidEntry invalid = new InvalidEntry();
                            invalid.fullPath = dir;
                            invalid.invalidReason = "Directory did not contain an Extended folder";
                            string[] reasons = {invalid.fullPath, invalid.invalidReason};
                            lvInvalidItems.Items.Add(new ListViewItem(reasons, "directory"));
                        }


                }

            }
            finally
            {

                lvInvalidItems.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                lvInvalidItems.Enabled = true;
                Cursor.Current = currentCursor;
                    
            }
        }