Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Linq;
- using System.Text;
- using static System.Console;
- namespace _1412_18
- {
- class MyDir
- {
- public static void Save(FileInfo fi) {
- using (FileStream fs = fi.Open(FileMode.Create, FileAccess.Write, FileShare.None))
- {
- string str = "Несе Галина воду";
- byte[] bs = Encoding.Unicode.GetBytes(str);
- fs.Write(bs, 0, bs.Length);
- WriteLine($"File {fi.FullName} save");
- }
- }
- public static string Load(FileInfo fi)
- {
- using (FileStream fo = fi.OpenRead())
- {
- byte[] bs = new byte[fo.Length];
- fo.Read(bs, 0, bs.Length);
- string str =Encoding.Unicode.GetString(bs);
- WriteLine($"File {fi.FullName} is read");
- return str;
- }
- }
- static void InfoDisk()
- {
- DriveInfo[] drives = DriveInfo.GetDrives();
- foreach (DriveInfo item in drives)
- {
- WriteLine($"Name {item.Name} ");
- WriteLine($"DriveType {item.DriveType} ");
- if (item.IsReady)
- {
- WriteLine($"TotalSize {item.TotalSize} ");
- WriteLine($"TotalFreeSpace {item.TotalFreeSpace} ");
- WriteLine($"VolumeLabel {item.VolumeLabel} ");
- WriteLine($"RootDirectory {item.RootDirectory} ");
- }
- }
- }
- static void DirInfo()
- {
- DirectoryInfo dir = new DirectoryInfo(@"d:\");
- if (dir.Exists)
- {
- WriteLine(dir.FullName);
- WriteLine(dir.CreationTime);
- foreach (var item in dir.GetDirectories())
- {
- WriteLine("folder -> "+ item);
- }
- foreach (var item in dir.GetFiles("*.jpg"))
- {
- WriteLine("file -> " + item);
- }
- }
- else
- {
- WriteLine("Not foud");
- }
- }
- public static void Run() {
- //DirInfo();
- InfoDisk();
- DirectoryInfo dir = new DirectoryInfo(@"d:\test");
- if (!dir.Exists)
- dir.Create();
- DirectoryInfo dir1 = dir.CreateSubdirectory("subdir1");
- WriteLine(dir1.FullName);
- FileInfo finfo = new FileInfo(dir1+@"\new.bin");
- Save(finfo);
- WriteLine(Load(finfo));
- //string newfolder = @"D:\test10";
- //if (Directory.Exists(newfolder) == false)
- // dir.MoveTo(newfolder);
- try
- {
- dir1.Delete(true);
- }
- catch (Exception e) {
- WriteLine(e.Message);
- }
- string fname = "test.txt";
- FileInfo iffile = new FileInfo(fname);
- if (iffile.Exists)
- {
- WriteLine("FullName -> " + iffile.FullName);
- WriteLine("CreationTime -> " + iffile.CreationTime);
- WriteLine("Size -> " + iffile.Length);
- // string text = File.ReadAllText(iffile.FullName);
- //WriteLine(text);
- string[] arrstr = File.ReadAllLines(iffile.FullName);
- foreach (var item in arrstr)
- {
- WriteLine(item);
- }
- iffile.Delete();
- WriteLine($"File {fname} is deleted");
- }
- else {
- string[] arrstr = { "Я", "не", "виконую", "домашню", "роботу", ", так як", "я", "ледарюга", "!!!" };
- File.WriteAllLines(fname,arrstr);
- //string tt = "Жили у бабусі два веселих гусі";
- //File.WriteAllText(iffile.FullName, tt);
- File.AppendAllText(iffile.FullName, "І ще два гусі");
- WriteLine($"File {fname} is created");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement