.NET 3.x Подсчет кол-ва папок и подпапок - C#
Формулировка задачи:
Всем привет, делал прогу, которая считает кол-во папок и подпапок. Так вот че-то не все работает. Сейчас можно в бета тесте посмотреть(без кода правда) вот почемуто глючит. вот код:
некотрые части вырезаны..
Листинг программы
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- string[] GetDirectories;
- int a = 0;
- int i = 0;
- int b = 0;
- private void Form1_Load(object sender, EventArgs e)
- {
- comboBox1.Items.Add(@"D:\");
- comboBox1.Items.Add(@"C:\");
- comboBox1.Items.Add(@"E:\");
- comboBox1.Items.Add(@"H:\");
- comboBox1.Items.Add(@"I:\");
- }
- private void button1_Click(object sender, EventArgs e)
- {
- b = 0;
- GetDirectories = Directory.GetDirectories(Convert.ToString(comboBox1.SelectedItem));
- timer1.Enabled = true;
- }
- public void Scan()
- {
- foreach (string SetDirectories1 in GetDirectories)
- {
- a += 1;
- textBox1.Text = Convert.ToString(a);
- listBox1.Items.Add(SetDirectories1);
- listBox1.TopIndex = listBox1.Items.Count - 1;
- }
- i += 1;
- }
- public void Peredacha()
- {
- GetDirectories = null;
- try
- {
- GetDirectories = Directory.GetDirectories(Convert.ToString(listBox1.Items[i]));
- }
- catch
- {
- GetDirectories = Directory.GetDirectories(Convert.ToString(listBox1.Items[i-1]));
- }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (b == 0)
- {
- try
- {
- Scan();
- Peredacha();
- }
- catch
- {
- timer1.Stop();
- // a = 0;
- //i = 0;
- b = 1;
- }
- }
- else { MessageBox.Show("Error"); b = 1; timer1.Stop(); break; }
- }
- }
Решение задачи: «.NET 3.x Подсчет кол-ва папок и подпапок»
textual
Листинг программы
- int KolDir(string FolderName)
- {
- int res = 1;
- try
- {
- foreach (string subdir in Directory.GetDirectories(FolderName))
- {
- res += KolDir(subdir);
- }
- }
- catch (Exception ex)
- {
- }
- return res;
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д