Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace FilesAndExceptions
- {
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- public class Program
- {
- public static void Main(string[] args)
- {
- //if (!File.Exists("myfile.txt"))
- //{
- // File.Create("myfile.txt");
- ////}
- ////var text = File.ReadAllText("myfile.txt");
- ////File.Move("myfile.txt", "../anotherfile.txt"); // renaming and moving a file
- //Console.WriteLine(text);
- //var file = "myfile.txt";
- //var lines = File.ReadAllLines(file);
- //var oddLines = new List<string>();
- //if (!File.Exists("result.txt"))
- //{
- // File.Create("result.txt");
- //}
- //for (int i = 0; i < lines.Length; i++)
- //{
- // if (i % 2 != 0)
- // {
- // oddLines.Add(lines[i]);
- // }
- //}
- //File.WriteAllLines("result.txt", oddLines);
- //var lines = File.ReadAllLines(file);
- //var linesWithNumbers = new List<string>();
- //for (int i = 0; i < lines.Length; i++)
- //{
- // linesWithNumbers.Add($"{i + 1}. {lines[i]}");
- //}
- //File.WriteAllLines("result.txt", linesWithNumbers);
- //var words = File.ReadAllText("words.txt")
- // .Split(new[] { ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries)
- // .Select(s => s.ToLower())
- // .ToArray();
- //var text = File.ReadAllText("text.txt").Split(new[] { ' ', '.', ',', '!', '?', '-', '\'', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)
- // .Select(s => s.ToLower())
- // .ToArray();
- //var result = new Dictionary<string, int>();
- //for (int i = 0; i < words.Length; i++)
- //{
- // var currentWordCount = 0;
- // var currentWord = words[i];
- // for (int j = 0; j < text.Length; j++)
- // {
- // if (currentWord == text[j])
- // {
- // currentWordCount++;
- // }
- // }
- // result[currentWord] = currentWordCount;
- //}
- //var sortedResult = result
- // .OrderByDescending(kvp => kvp.Value)
- // .Select(kvp => $"{kvp.Key} - {kvp.Value}")
- // .ToArray();
- //File.WriteAllLines("result.txt", sortedResult);
- //var dir = Directory.GetCurrentDirectory();
- //var dirInfo = new DirectoryInfo(dir);
- //var parent = dirInfo.Parent;
- //var allDirsInParent = parent.GetDirectories();
- //foreach (var dirc in allDirsInParent)
- //{
- // Console.WriteLine(dirc);
- //}
- //var totalLength = Directory.GetFiles("Debug")
- // .Select(f => new FileInfo(f))
- // .Sum(f => f.Length/ 1024.0 / 1024.0);
- //double sum = 0;
- //foreach (var file in files)
- //{
- // FileInfo fileInfo = new FileInfo(file);
- // sum += fileInfo.Length;
- //}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement