using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace ch10_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")

                if (!Directory.Exists(textBox1.Text))
                {
                    Directory.CreateDirectory(textBox1.Text);
                    MessageBox.Show("Directory  created");
                }
                else
                    MessageBox.Show("Directory  exists");
            else
                MessageBox.Show("Please enter directory name in  TextBox");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
                if (Directory.Exists(textBox1.Text))
                {
                    Directory.Delete(textBox1.Text);
                    MessageBox.Show("Directory  deleted");
                }
                else
                    MessageBox.Show("Directory not exists");
            else
                MessageBox.Show("Please enter directory name in  textBox1");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            if (textBox1.Text != "")
            {
                listBox1.Show();
                if (Directory.Exists(textBox1.Text))
                {
                    string[] subDir = Directory.GetDirectories(textBox1.Text);
                    foreach (string dir in subDir)
                    {
                        listBox1.Items.Add(dir);
                    }
                }
                else
                    MessageBox.Show("Directory not exists");
            }
            else
                MessageBox.Show("Please enter directory name in  textBox1");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            if (textBox1.Text != "")
            {
                listBox1.Show();
                if (Directory.Exists(textBox1.Text))
                {
                    string[] files = Directory.GetFiles(textBox1.Text);
                    foreach (string file in files)
                        listBox1.Items.Add(file);

                }
                else
                    MessageBox.Show("Directory not exists");
            }
            else
                MessageBox.Show("Please enter directory name in  textBox1");
        }
    }
}
