|
@@ -84,7 +84,7 @@ Process finished with exit code 0.
|
|
|
```
|
|
|
### Создание каталога
|
|
|
```
|
|
|
-string path = @"C:\SomeDir";
|
|
|
+string path = @"C:\Users\mister pig\Documents";
|
|
|
string subpath = @"program\avalon";
|
|
|
DirectoryInfo dirInfo = new DirectoryInfo(path);
|
|
|
if (!dirInfo.Exists)
|
|
@@ -108,7 +108,7 @@ Console.WriteLine($"Полное название каталога: {dirInfo.Ful
|
|
|
Console.WriteLine($"Время создания каталога: {dirInfo.CreationTime}");
|
|
|
Console.WriteLine($"Корневой каталог: {dirInfo.Root}");
|
|
|
```
|
|
|
-Результата работы:
|
|
|
+Результат работы:
|
|
|
```
|
|
|
Название каталога: Program Files
|
|
|
Полное название каталога: C:\Program Files
|
|
@@ -119,7 +119,7 @@ Process finished with exit code 0.
|
|
|
```
|
|
|
### Удаление каталога
|
|
|
```
|
|
|
-string dirName = @"C:\SomeFolder";
|
|
|
+string dirName = @"C:\Users\mister pig\Documents\panda";
|
|
|
|
|
|
try
|
|
|
{
|
|
@@ -134,14 +134,14 @@ catch (Exception ex)
|
|
|
```
|
|
|
Результат работы:
|
|
|
```
|
|
|
-Could not find a part of the path 'C:\SomeFolder'.
|
|
|
+Каталог удален
|
|
|
|
|
|
Process finished with exit code 0.
|
|
|
```
|
|
|
### Перемещение каталога
|
|
|
```
|
|
|
-string oldPath = @"C:\SomeFolder";
|
|
|
-string newPath = @"C:\SomeDir";
|
|
|
+string oldPath = @"C:\Users\mister pig\Documents\program";
|
|
|
+string newPath = @"C:\Users\mister pig\Documents\panda";
|
|
|
DirectoryInfo dirInfo = new DirectoryInfo(oldPath);
|
|
|
if (dirInfo.Exists && Directory.Exists(newPath) == false)
|
|
|
{
|
|
@@ -155,7 +155,7 @@ Process finished with exit code 0.
|
|
|
## Работа с файлами. Классы File и FileInfo
|
|
|
### Получение информации о файле
|
|
|
```
|
|
|
-string path = @"C:\apache\hta.txt";
|
|
|
+string path = @"C:\Users\mister pig\Documents\panda\panda.txt";
|
|
|
FileInfo fileInf = new FileInfo(path);
|
|
|
if (fileInf.Exists)
|
|
|
{
|
|
@@ -166,11 +166,15 @@ if (fileInf.Exists)
|
|
|
```
|
|
|
Результат работы:
|
|
|
```
|
|
|
+Имя файла: panda.txt
|
|
|
+Время создания: 08.03.2024 20:04:20
|
|
|
+Размер: 47
|
|
|
+
|
|
|
Process finished with exit code 0.
|
|
|
```
|
|
|
### Удаление файла
|
|
|
```
|
|
|
-string path = @"C:\apache\hta.txt";
|
|
|
+string path = @"C:\Users\mister pig\Documents\panda\bamboo.txt";
|
|
|
FileInfo fileInf = new FileInfo(path);
|
|
|
if (fileInf.Exists)
|
|
|
{
|
|
@@ -185,14 +189,14 @@ Process finished with exit code 0.
|
|
|
```
|
|
|
### Перемещение файла
|
|
|
```
|
|
|
-string path = @"C:\apache\hta.txt";
|
|
|
-string newPath = @"C:\SomeDir\hta.txt";
|
|
|
+string path = @"C:\Users\mister pig\Documents\panda\panda.txt";
|
|
|
+string newPath = @"C:\Users\mister pig\Documents\pororo.txt";
|
|
|
FileInfo fileInf = new FileInfo(path);
|
|
|
if (fileInf.Exists)
|
|
|
{
|
|
|
- fileInf.MoveTo(newPath);
|
|
|
- // альтернатива с помощью класса File
|
|
|
- // File.Move(path, newPath);
|
|
|
+ fileInf.MoveTo(newPath);
|
|
|
+ // альтернатива с помощью класса File
|
|
|
+ // File.Move(path, newPath);
|
|
|
}
|
|
|
```
|
|
|
Результат работы:
|
|
@@ -201,14 +205,14 @@ Process finished with exit code 0.
|
|
|
```
|
|
|
### Копирование файла
|
|
|
```
|
|
|
-string path = @"C:\apache\hta.txt";
|
|
|
-string newPath = @"C:\SomeDir\hta.txt";
|
|
|
+string path = @"C:\Users\mister pig\Documents\panda\bamboo.txt";
|
|
|
+string newPath = @"C:\Users\mister pig\Documents\panda\totoro.txt";
|
|
|
FileInfo fileInf = new FileInfo(path);
|
|
|
if (fileInf.Exists)
|
|
|
{
|
|
|
- fileInf.CopyTo(newPath, true);
|
|
|
- // альтернатива с помощью класса File
|
|
|
- // File.Copy(path, newPath, true);
|
|
|
+ fileInf.CopyTo(newPath, true);
|
|
|
+ // альтернатива с помощью класса File
|
|
|
+ // File.Copy(path, newPath, true);
|
|
|
}
|
|
|
```
|
|
|
Результат работы:
|
|
@@ -414,7 +418,7 @@ Process finished with exit code 0.
|
|
|
FileStream fstream = null;
|
|
|
try
|
|
|
{
|
|
|
- fstream = new FileStream(@"D:\note3.dat", FileMode.OpenOrCreate);
|
|
|
+ fstream = new FileStream(@"C:\Users\mister pig\Documents\panda\baobab.txt", FileMode.OpenOrCreate);
|
|
|
// операции с потоком
|
|
|
}
|
|
|
catch(Exception ex)
|
|
@@ -443,7 +447,7 @@ namespace HelloApp
|
|
|
{
|
|
|
static void Main(string[] args)
|
|
|
{
|
|
|
- string writePath = @"C:\SomeDir\hta.txt";
|
|
|
+ string writePath = @"C:\Users\mister pig\Documents\panda\totoro.txt";
|
|
|
|
|
|
string text = "Привет мир!\nПока мир...";
|
|
|
try
|
|
@@ -488,7 +492,7 @@ namespace HelloApp
|
|
|
{
|
|
|
static async Task Main(string[] args)
|
|
|
{
|
|
|
- string writePath = @"C:\SomeDir\hta2.txt";
|
|
|
+ string writePath = @"C:\Users\mister pig\Documents\panda\totoro.txt";
|
|
|
|
|
|
string text = "Привет мир!\nПока мир...";
|
|
|
try
|
|
@@ -527,7 +531,7 @@ using System;
|
|
|
using System.IO;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
-string path = @"C:\SomeDir\hta.txt";
|
|
|
+string path = @"C:\Users\mister pig\Documents\panda\bamboo.txt";
|
|
|
|
|
|
try
|
|
|
{
|
|
@@ -548,20 +552,14 @@ catch (Exception e)
|
|
|
```
|
|
|
Результат работы:
|
|
|
```
|
|
|
-Привет мир!
|
|
|
-Пока мир...
|
|
|
-Дозапись
|
|
|
-4,5
|
|
|
-Привет мир!
|
|
|
-Пока мир...
|
|
|
-Дозапись
|
|
|
-4,5
|
|
|
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
|
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
|
|
|
|
Process finished with exit code 0.
|
|
|
```
|
|
|
### Считаем текст из файла построчно:
|
|
|
```
|
|
|
-string path= @"C:\SomeDir\hta.txt";
|
|
|
+string path= @"C:\Users\mister pig\Documents\panda\bamboo.txt";
|
|
|
|
|
|
using (StreamReader sr = new StreamReader(path, System.Text.Encoding.Default))
|
|
|
{
|
|
@@ -583,14 +581,8 @@ using (StreamReader sr = new StreamReader(path, System.Text.Encoding.Default))
|
|
|
```
|
|
|
Результат работы:
|
|
|
```
|
|
|
-Привет мир!
|
|
|
-Пока мир...
|
|
|
-Дозапись
|
|
|
-4,5
|
|
|
-Привет мир!
|
|
|
-Пока мир...
|
|
|
-Дозапись
|
|
|
-4,5
|
|
|
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
|
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
|
|
|
|
Process finished with exit code 0.
|
|
|
```
|
|
@@ -619,7 +611,7 @@ class Program
|
|
|
states[0] = new State("Германия", "Берлин", 357168, 80.8);
|
|
|
states[1] = new State("Франция", "Париж", 640679, 64.7);
|
|
|
|
|
|
- string path= @"C:\SomeDir\states.dat";
|
|
|
+ string path= @"C:\Users\mister pig\Documents\panda\baobab.txt";
|
|
|
|
|
|
try
|
|
|
{
|
|
@@ -664,6 +656,7 @@ class Program
|
|
|
```
|
|
|
Страна: Германия столица: Берлин площадь 357168 кв. км численность населения: 80,8 млн. чел.
|
|
|
Страна: Франция столица: Париж площадь 640679 кв. км численность населения: 64,7 млн. чел.
|
|
|
+Unable to read beyond the end of the stream.
|
|
|
|
|
|
Process finished with exit code 0.
|
|
|
```
|