Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace Example
- {
- class Program
- {
- static void Show(DirectoryInfo dir)
- {
- Console.WriteLine("***** {0} *****", dir.Name);
- Console.WriteLine("FullName: {0}", dir.FullName);
- Console.WriteLine();
- FileInfo[] files = dir.GetFiles();
- if (files.Length != 0)
- {
- Console.WriteLine("Найдено файлов: {0}\n", files.Length);
- foreach (FileInfo item in files)
- {
- Console.WriteLine("File: {0} Size: {1}",item.Name, item.Length);
- }
- }
- Console.WriteLine();
- DirectoryInfo[] subDirects = dir.GetDirectories();
- if (subDirects.Length != 0)
- {
- Console.WriteLine("Найдено подкаталогов: {0}", subDirects.Length);
- foreach (DirectoryInfo item in subDirects)
- {
- Show(item);
- }
- }
- }
- static void Main()
- {
- DirectoryInfo dir = new DirectoryInfo(@"C:\temp");
- dir.CreateSubdirectory("K1");
- dir.CreateSubdirectory("K2");
- FileInfo f1 = new FileInfo(@"C:\temp\K1\t1.txt");
- using (StreamWriter output = new StreamWriter(f1.Create()))
- {
- output.WriteLine("Иванов Иван Иванович, 1965 года рождения, место жительства г. Саратов");
- }
- FileInfo f2 = new FileInfo(@"C:\temp\K1\t2.txt");
- using (StreamWriter output = new StreamWriter(f2.Create()))
- {
- output.WriteLine("Петров Сергей Федорович, 1966 года рождения, место жительства г. Энгельс");
- }
- FileInfo f3 = new FileInfo(@"C:\temp\K2\t3.txt");
- using (StreamWriter output = new StreamWriter(f3.Create()))
- {
- using (StreamReader input = new StreamReader(@"C:\temp\K1\t1.txt"))
- {
- output.WriteLine(input.ReadLine());
- }
- using (StreamReader input = new StreamReader(@"C:\temp\K1\t2.txt",true))
- {
- output.WriteLine(input.ReadLine());
- }
- }
- f1.MoveTo(@"C:\temp\K2\t1.txt");
- f2.MoveTo(@"C:\temp\K2\t2.txt");
- DirectoryInfo dir1 = new DirectoryInfo(@"C:\temp\K2");
- dir1.MoveTo(@"C:\temp\ALL");
- DirectoryInfo dir2 = new DirectoryInfo(@"C:\temp\K1");
- dir2.Delete();
- Show(dir);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement