Esempio n. 1
0
        private FolderData set_json(string folder_path)
        {
            var folder_name = Path.GetFileName(folder_path);
            var folder_data = new FolderData(folder_name);

            folder_data.files = Directory.GetFiles(folder_path).Select(o => Path.GetFileName(o)).ToList();

            string[] folders = Directory.GetDirectories(folder_path);
            foreach (var folder in folders)
            {
                folder_data.folders.Add(set_json(folder));
            }
            return(folder_data);
        }
Esempio n. 2
0
        private void start_analyze_dir(object sender, System.EventArgs e)
        {
            var save_file_name = this.file_saving_name.Text;

            if (string.IsNullOrEmpty(save_file_name))
            {
                System.Windows.Forms.MessageBox.Show("please pick a name for your file");
                return;
            }
            var save_file_path = this.saving_dir.Text;

            if (string.IsNullOrEmpty(save_file_path))
            {
                System.Windows.Forms.MessageBox.Show("please pick a directory to save the file in");
                return;
            }
            else if (!Directory.Exists(save_file_path))
            {
                System.Windows.Forms.MessageBox.Show("the directory you choose to save files doesnt exist");
                return;
            }

            var analyze_dir = this.dir_to_analyze.Text;

            if (string.IsNullOrEmpty(analyze_dir))
            {
                System.Windows.Forms.MessageBox.Show("please pick a directory to analyze");
                return;
            }
            else if (!Directory.Exists(analyze_dir))
            {
                System.Windows.Forms.MessageBox.Show("the directory you choose to analyze doesnt exist");
                return;
            }


            this.progressBar1.Value = 0;
            this.progressBar1.Show();
            this.timer1.Start();

            root = set_json(analyze_dir);
            Console.Write(root);
            var save_full_name = string.Format(@"{0}\{1}.xls", save_file_path, save_file_name);

            CreateExcel(save_full_name, root);
        }
Esempio n. 3
0
        public void CreateExcel(string save_dir, FolderData folder_data)
        {
            var Error = false;
            var xlApp = new Microsoft.Office.Interop.Excel.Application();

            if (xlApp == null)
            {
                MessageBox.Show("Excel is not properly installed!!");
                return;
            }
            object misValue    = System.Reflection.Missing.Value;
            var    xlWorkBook  = xlApp.Workbooks.Add(misValue);
            var    xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

            folder_data.RestartStack();
            string file_content = folder_data.ConvertToSTR();

            string[] lines = file_content.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);

            var i = 1;

            foreach (var line in lines)
            {
                string[] splitted = line.Split(new string[] { "-" }, 2, StringSplitOptions.None);
                if (splitted.Count() > 1)
                {
                    xlWorkSheet.Cells[i, 1] = splitted[0];
                    xlWorkSheet.Cells[i, 2] = splitted[1];
                    i++;
                }
            }
            try
            {
                xlWorkBook.SaveAs(save_dir,
                                  Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal,
                                  misValue, misValue, misValue, misValue,
                                  Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive,
                                  misValue, misValue, misValue, misValue, misValue);
            }
            catch
            {
                Error = true;
            }
            xlWorkBook.Close(true, misValue, misValue);
            xlApp.Quit();

            Marshal.ReleaseComObject(xlWorkSheet);
            Marshal.ReleaseComObject(xlWorkBook);
            Marshal.ReleaseComObject(xlApp);


            this.progressBar1.Increment(10000);
            if (!Error)
            {
                MessageBox.Show(string.Format("Excel file created , you can find the file {0}", save_dir));
            }
            else
            {
                MessageBox.Show(string.Format("Failed to save file to {0}", save_dir));
            }

            this.progressBar1.Hide();
        }