Пример #1
0
        //const string SALabel = "SideAngle";
        //const string SAMarkInFile = "SA";


        public static List <string> SearchFileAndCreateAllInOneCSV(string pathDirectory, bool searchRecursive, string CSV_AllInOneFileName)
        {
            SearchOption searchOption = SearchOption.TopDirectoryOnly;

            if (searchRecursive == true)
            {
                searchOption = SearchOption.AllDirectories;
            }

            return(FileCSV.SearchFileAndCreateAllInOneCSV(pathDirectory, FileCSV.SearchPattern, searchOption, CSV_AllInOneFileName));
        }
Пример #2
0
        private static string ChangeCurrentFileNameToNumberAoA(string fileNameHistoryWithAoA)
        {
            string AoANumber = fileNameHistoryWithAoA;

            if (AoANumber.Contains(FileCSV.AoAMarkInFile) == true)
            {
                int AoAIndex       = AoANumber.IndexOf(FileCSV.AoAMarkInFile);
                int extensionIndex = AoANumber.IndexOf(FileCSV.CSVExtension);
                AoANumber = AoANumber.Substring(AoAIndex + FileCSV.AoAMarkInFile.Count(), extensionIndex - AoAIndex - FileCSV.AoAMarkInFile.Count());
            }

            AoANumber = FileCSV.ChangeSeparators(AoANumber);
            return(AoANumber);
        }
        private void buttonExecute_Click(object sender, EventArgs e)
        {
            textBoxOut.Text = "Processing...";


            if (CheckPaths(this.directoryPathsSelected) == false)
            {
                this.buttonCSVOpen_Click(sender, e);
                return;
            }



            List <List <string> > directoryPathsList = new List <List <string> >();

            foreach (string path in this.directoryPathsSelected)
            {
                directoryPathsList.Add(FileCSV.SearchFileAndCreateAllInOneCSV(path, checkBoxcheckBoxSearchSubdirectories.Checked, textBoxFileNameHistory.Text));
            }



            if (checkBoxCreateComparisonXLSX.Checked == true)
            {
                try
                {
                    List <string> directoryPaths = ConvertListListStringToListString(directoryPathsList);

                    FileXLSX.SaveXLSX(this.saveFileDialogMain.FileName, directoryPaths, textBoxFileNameHistory.Text);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }



            textBoxOut.Text = "Successfully done!";
            this.directoryPathsSelected.Clear();
        }
Пример #4
0
        private static List <string> SearchFileAndCreateAllInOneCSV(string pathDirectory, string searchPattern, SearchOption searchOption, string CSV_AllInOneFileName)
        {
            IEnumerable <string> files;
            List <string>        dictionaryPaths = new List <string>();

            //The EnumerateFiles (.NET 4.0 and later) and GetFiles methods differ as follows:
            //When you use EnumerateFiles, you can start enumerating the collection of names before the whole collection is returned;
            //when you use GetFiles, you must wait for the whole array of names to be returned before you can access the array.
            //Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
            try
            {
                files = Directory.EnumerateFiles(pathDirectory, searchPattern, searchOption);
            }
            catch (Exception ex)
            {
                FileCSV.WriteExceptionToDebug(ex);
                return(dictionaryPaths);
            }



            //delete all History_All.csv files from directories. Otherwise the lines will be added to existed files.
            try
            {
                IEnumerable <string> filesHistoryAll;
                filesHistoryAll = Directory.EnumerateFiles(pathDirectory, CSV_AllInOneFileName, searchOption);
                foreach (string currentFile in filesHistoryAll)
                {
                    File.Delete(currentFile);
                }
            }
            catch (Exception ex)
            {
                FileCSV.WriteExceptionToDebug(ex);
                return(dictionaryPaths);
            }



            foreach (string currentFile in files)
            {
                FileInfo infoFile = new FileInfo(currentFile);
                if (infoFile.Name.Substring(0, 7) == FileCSV.FileNameBeginning)
                {
                    try
                    {
                        string lastLine = FileCSV.OpenCSVAndGetLastLine(currentFile);
                        lastLine = FileCSV.ChangeSeparators(lastLine);
                        string directoryName = FileCSV.GetDirectory(currentFile);
                        FileCSV.AddToDirectoryList(ref dictionaryPaths, FileCSV.GetDirectoryPath(currentFile));
                        string historyAllInOnePath = directoryName + "\\" + CSV_AllInOneFileName;
                        string AoANumber           = FileCSV.ChangeCurrentFileNameToNumberAoA(infoFile.Name);
                        string lastLineWhole       = AoANumber + FileCSV.SeparatorOut + lastLine;
                        if (File.Exists(historyAllInOnePath) == false)
                        {
                            string header = FileCSV.OpenCSVAndGetFirstLine(currentFile);
                            header = "\"" + AoALabel + "\"" + FileCSV.SeparatorOut + FileCSV.ChangeSeparators(header);
                            FileCSV.WriteLineToCSVWithHeaderFirst(historyAllInOnePath, lastLineWhole, header);
                        }
                        else
                        {
                            FileCSV.WriteLineToCSV(historyAllInOnePath, lastLineWhole);
                        }
                    }
                    catch (Exception ex)
                    {
                        FileCSV.WriteExceptionToDebug(ex);
                        continue;
                    }
                }
            }

            return(dictionaryPaths);
        }