Esempio n. 1
0
        private void PrintFoldersAndFiles()
        {
            ClearOutputAndStatus();

            if (!Directory.Exists(folderTextBox.Text))
            {
                statusBar.SetStatusError("Folder does not exist.");
                return;
            }

            var folderCount = 0;

            if (foldersToolStripMenuItem.Checked)
            {
                folderCount = PrintFolders(folderTextBox.Text);
            }

            var fileCount = 0;

            if (filesToolStripMenuItem.Checked)
            {
                var options      = CreateFileDisplayOptions();
                var suffixFilter = new SuffixFilter(suffixTextBox.Text);

                fileCount = PrintFiles(folderTextBox.Text, suffixFilter, options);
            }

            statusBar.SetCountStatus(fileCount, folderCount);
        }
Esempio n. 2
0
        private int PrintFiles(string folderPath, SuffixFilter suffixFilter, FileDisplayOptions fileDisplayOptions)
        {
            statusBar.SetStatus("Performing search...");

            var dirInfo = new DirectoryInfo(folderPath);

            var fileCount = 0;

            var fileHash = hashTextBox.Text.Trim();

            if (!string.IsNullOrEmpty(fileHash))
            {
                var matches = ChecksumService.GetMd5Matches(folderTextBox.Text, fileHash);

                foreach (var match in matches)
                {
                    var fileDetail = new FileDetail(new FileInfo(match), fileDisplayOptions, fileCount + 1, matches.Count);

                    outputTextBox.PrintLine(fileDetail.ToString());
                    fileCount++;
                }
            }
            else
            {
                var fileInfos = dirInfo.GetFiles("*." + suffixFilter);

                foreach (var fileInfo in fileInfos)
                {
                    var fileDetail = new FileDetail(fileInfo, fileDisplayOptions, fileCount + 1, fileInfos.Length);

                    outputTextBox.PrintLine(fileDetail.ToString());
                    fileCount++;
                }
            }

            return(fileCount);
        }