Пример #1
0
    static void Main(string[] args)
    {
        try
        {
            /*
             * Console.WriteLine("Unesi put do direktorija:");
             * string DirectoryName = Console.ReadLine();
             *
             * Console.WriteLine("Unesi ekstenziju:");
             * string MyExtension = Console.ReadLine();
             */
            string DirectoryName = "D:\\Users\\Zvone\\FER\\Nastava\\FER 2 - ASP\\Domace zadace\\DZ 1";
            string MyExtension   = ".c";

            EnumerateFiles EnumFiles = new EnumerateFiles(DirectoryName);
            EnumFiles.Enumerate();

            Console.WriteLine("{0,-25} {1}", "Ukupno poddirektorija:", EnumFiles.Directories);
            Console.WriteLine("{0,-25} {1}", "Ukupno fileova:", EnumFiles.Files);
            Console.WriteLine();
            Console.WriteLine("{0,-35} {1,-10} {2, -10} {3, -10} {4,-10}", "Path:", "Ukupno:", "Praznih:", "Komentara:", "Miješano");

            FileCodeInfo Info;
            long         Total = 0;
            for (int i = 0; i < EnumFiles.Duljina; i++)
            {
                if (((FileInfo)EnumFiles[i]).Extension == MyExtension)
                {
                    Data1 data = new Data1((FileInfo)EnumFiles[i]);
                    Info = FileAnalyzer.AnalyseFile(data);
                    Console.WriteLine("{0,-45} {1,-5} {2, -5} {3, -5} {4,-5}", Info.FileName, Info.NumberOfLines, Info.NumberOfEmptyLines, Info.NumberOfComments, Info.NumberOfMixedLines);
                    Total += Info.NumberOfLines;
                }
            }
            Console.WriteLine("\n\nTOTAL {0}", Total);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
        finally
        {
            Console.ReadLine();
        }
    }
Пример #2
0
    static void Main(string[] args)
    {
        try
        {
            /*
             * Console.WriteLine("Unesi put do direktorija:");
             * string DirectoryName = Console.ReadLine();
             *
             * Console.WriteLine("Unesi ekstenziju:");
             * string MyExtension = Console.ReadLine();
             */
            string DirectoryName = "C:\\TestDir";
            string MyExtension   = ".txt";

            EnumerateFiles EnumFiles = new EnumerateFiles(DirectoryName);
            EnumFiles.Enumerate();

            Console.WriteLine("{0,-25} {1}", "Ukupno poddirektorija:", EnumFiles.Directories);
            Console.WriteLine("{0,-25} {1}", "Ukupno fileova:", EnumFiles.Files);
            Console.WriteLine();
            Console.WriteLine("{0,-35} {1,-10} {2, -10} {3, -10} {4,-10}", "Path:", "Ukupno:", "Praznih:", "Komentara:", "Miješano");

            FileCodeInfo Info;
            for (int i = 0; i < EnumFiles.Duljina; i++)
            {
                if (((FileInfo)EnumFiles[i]).Extension == MyExtension)
                {
                    Data1 data = new Data1((FileInfo)EnumFiles[i]);
                    Info = FileAnalyzer.AnalyseFile(data);
                    Console.WriteLine("{0,-35} {1,-10} {2, -10} {3, -10} {4,-10}", Info.FileName, Info.NumberOfLines, Info.NumberOfEmptyLines, Info.NumberOfComments, Info.NumberOfMixedLines);
                }
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
        finally
        {
            Console.ReadLine();
        }
    }
Пример #3
0
        private void AnalyseButton_Click(object sender, EventArgs e)
        {
            try
            {
                listView1.Items.Clear(); //
                listExtension.Clear();   //isprazni listu

                DirectoryName = DirectoryBox.Text;
                if (DirectoryName == "")
                {
                    throw new DirectoryNotFoundException("Enter directory path!");
                }

                //pregledavam checkirane ekstenzije
                if (ExtensionC.Checked)
                {
                    listExtension.Add(ExtensionC.Text);
                }
                if (ExtensionH.Checked)
                {
                    listExtension.Add(ExtensionH.Text);
                }
                if (ExtensionCPP.Checked)
                {
                    listExtension.Add(ExtensionCPP.Text);
                }
                if (ExtensionJAVA.Checked)
                {
                    listExtension.Add(ExtensionJAVA.Text);
                }
                if (ExtensionCS.Checked)
                {
                    listExtension.Add(ExtensionCS.Text);
                }

                EnumerateFiles EnumFiles = new EnumerateFiles(DirectoryName);
                EnumFiles.Enumerate();

                //ispis (broj datoteka, direktorija)
                Directories.Text = (EnumFiles.Directories).ToString();
                Files.Text       = (EnumFiles.Files).ToString();


                FileCodeInfo Info;

                al.Clear();
                //BindingList<FileCodeInfo> bindList= new BindingList<FileCodeInfo>();

                for (int i = 0; i < EnumFiles.Duljina; i++)
                {
                    if (listExtension.Contains(((FileInfo)EnumFiles[i]).Extension))
                    {
                        Data1 data = new Data1((FileInfo)EnumFiles[i]);
                        Info = FileAnalyzer.AnalyseFile(data);

                        al.Add(Info);
                        //bindList.Add(Info);
                        //Binding_source.Add(Info);
                        //ResultRow = new string[] { Info.FileName, ((FileInfo)EnumFiles[i]).Extension, (Info.NumberOfLines).ToString(), (Info.NumberOfEmptyLines).ToString(), (Info.NumberOfComments).ToString(), (Info.NumberOfMixedLines).ToString() };
                        //ResultGrid.Rows.Add(ResultRow);

                        data.Dispose();
                    }
                }

                for (int j = 0; j < al.Count; j++)
                {
                    ListViewItem listItem = new ListViewItem(al[j].FileName);
                    listItem.SubItems.Add(al[j].Extension);
                    listItem.SubItems.Add((al[j].NumberOfLines).ToString());
                    listItem.SubItems.Add((al[j].NumberOfEmptyLines).ToString());
                    listItem.SubItems.Add((al[j].NumberOfComments).ToString());
                    listItem.SubItems.Add((al[j].NumberOfMixedLines).ToString());
                    listView1.Items.Add(listItem);
                }
            }
            catch (Exception ex)
            {
                //alert
                MessageBox.Show(ex.Message);
            }
        }
Пример #4
0
        private void AnalyseButton_Click(object sender, EventArgs e)
        {
            try
            {
                ResultGrid.RowCount = 1; //prebriše dosadašnje rezultate (ako ih je bilo)
                listExtension.Clear();   //isprazni listu

                DirectoryName = DirectoryBox.Text;
                if (DirectoryName == "")
                {
                    throw new DirectoryNotFoundException("Enter directory path!");
                }

                //pregledavam checkirane ekstenzije
                if (ExtensionC.Checked)
                {
                    listExtension.Add(ExtensionC.Text);
                }
                if (ExtensionH.Checked)
                {
                    listExtension.Add(ExtensionH.Text);
                }
                if (ExtensionCPP.Checked)
                {
                    listExtension.Add(ExtensionCPP.Text);
                }
                if (ExtensionJAVA.Checked)
                {
                    listExtension.Add(ExtensionJAVA.Text);
                }
                if (ExtensionCS.Checked)
                {
                    listExtension.Add(ExtensionCS.Text);
                }

                EnumerateFiles EnumFiles = new EnumerateFiles(DirectoryName);
                EnumFiles.Enumerate();

                //ispis (broj datoteka, direktorija)
                Directories.Text = (EnumFiles.Directories).ToString();
                Files.Text       = (EnumFiles.Files).ToString();

                //ispis rezultata za pojedinu datoteku
                FileCodeInfo Info;
                string[]     ResultRow;
                for (int i = 0; i < EnumFiles.Duljina; i++)
                {
                    if (listExtension.Contains(((FileInfo)EnumFiles[i]).Extension))
                    {
                        Data1 data = new Data1((FileInfo)EnumFiles[i]);
                        Info      = FileAnalyzer.AnalyseFile(data);
                        ResultRow = new string[] { Info.FileName, ((FileInfo)EnumFiles[i]).Extension, (Info.NumberOfLines).ToString(), (Info.NumberOfEmptyLines).ToString(), (Info.NumberOfComments).ToString(), (Info.NumberOfMixedLines).ToString() };
                        ResultGrid.Rows.Add(ResultRow);
                        data.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                //alert
                MessageBox.Show(ex.Message);
            }
        }