Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

ПРЕЗЕНТАЦИЯ_С# / си / ПРИМЕР_ФАЙЛОВ_КЛАСС_DIRECTORY

.doc
Скачиваний:
48
Добавлен:
17.04.2015
Размер:
291.84 Кб
Скачать

// Использование методов класса DIRECTORY

using System; using System.Collections.Generic; using System.ComponentModel;

using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Windows.Forms; using System.IO;

namespace WindowsFormsApplication20

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

string s = "C:\\" + textBox1.Text;

string s1 = s + "\\" + textBox2.Text + ".txt";

if ((Directory.Exists(s) == false) && (Directory.Exists(s + "\\Вторая директория") == false) && (File.Exists(s1) == false))

{

Directory.CreateDirectory(s);

Directory.CreateDirectory(s + "\\Вторая дирректория");

StreamWriter ff = File.CreateText(s1);

ff.Close();

MessageBox.Show("Создана иерархия папок и файл");

}

else

{

MessageBox.Show("Данная папка уже существует");

}

StreamWriter ope = File.AppendText(s1);

ope.WriteLine(textBox3.Text);

ope.Close();

}

private void button2_Click(object sender, EventArgs e)

{

string s = "C:\\" + textBox1.Text;

string s1 = s + "\\" + textBox2.Text + ".txt";

if (Directory.Exists(s))

{

Directory.Delete(s, true);

MessageBox.Show("Удалили папку и ее содержимое");

}

else

{

MessageBox.Show("Этой папки нет");

} }}}