コード例 #1
0
        private void SearchFiles(string path, string filename)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(path);

            FileInfo[]      fileInfos      = directoryInfo.GetFiles("*" + filename + "*");
            DirectoryInfo[] directoryInfos = directoryInfo.GetDirectories("*" + filename + "*");
            listBox.Items.Clear();
            MyDirectory        myDir      = new MyDirectory(path);
            List <DiscElement> myElements = myDir.GetSubElements();

            foreach (DirectoryInfo directory in directoryInfos)
            {
                foreach (DiscElement myElement in myElements)
                {
                    if (directory.Name == myElement.GetName())
                    {
                        DirectoryView newFolderView = new DirectoryView((MyDirectory)myElement);
                        newFolderView.DirectoryChanged += OnDirectoryChanged;
                        listBox.Items.Add(newFolderView);
                    }
                }
            }
            foreach (FileInfo file in fileInfos)
            {
                foreach (DiscElement myElement in myElements)
                {
                    if (file.Name == myElement.GetName())
                    {
                        FileView newElementView = new FileView((MyFile)myElement);
                        listBox.Items.Add(newElementView);
                    }
                }
            }
        }
コード例 #2
0
        public void LoadFiles(string path, bool sort)
        {
            if (!Directory.Exists(path))
            {
                MessageBox.Show("Błąd Ścieżki!");
                listBox.Items.Clear();
                return;
            }
            MyDirectory        myDir      = new MyDirectory(path);
            List <DiscElement> myElements = myDir.GetSubElements();

            listBox.Items.Clear();
            if (sort == true)
            {
                myElements = myElements.OrderBy(o => o.GetCreationTime()).ToList();
                List <DiscElement> myDirSorted  = new List <DiscElement>();
                List <DiscElement> myFileSorted = new List <DiscElement>();
                foreach (DiscElement orderingElement in myElements)
                {
                    if (orderingElement is MyDirectory)
                    {
                        myDirSorted.Add(orderingElement);
                    }
                    else
                    {
                        myFileSorted.Add(orderingElement);
                    }
                }
                myElements.Clear();
                foreach (DiscElement myDirectory in myDirSorted)
                {
                    myElements.Add(myDirectory);
                }
                foreach (DiscElement myFile in myFileSorted)
                {
                    myElements.Add(myFile);
                }
            }
            foreach (DiscElement myElement in myElements)
            {
                if (myElement is MyDirectory)
                {
                    DirectoryView newFolderView = new DirectoryView((MyDirectory)myElement);
                    newFolderView.DirectoryChanged += OnDirectoryChanged;
                    newFolderView.DirectoryDelete  += OnDeleteDirectory;
                    listBox.Items.Add(newFolderView);
                }
                else
                {
                    FileView newElementView = new FileView((MyFile)myElement);
                    newElementView.filedelete += OnDeleteClick;
                    listBox.Items.Add(newElementView);
                }
            }
        }
コード例 #3
0
        internal List <string> GetSelectedDirs()
        {
            List <string> selectedDirs = new List <string>();

            foreach (var dir in listBox.Items)
            {
                if (dir is DirectoryView)
                {
                    DirectoryView directoryView = (DirectoryView)dir;
                    if (directoryView.checkBox.IsChecked == true)
                    {
                        directoryView.checkBox.IsChecked = false;
                        selectedDirs.Add(directoryView.GetPath());
                    }
                }
            }

            return(selectedDirs);
        }