repl.it
@kironroy/

files

C#

working with files

fork
loading
Files
  • main.cs
  • main.exe
  • notes.txt
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.IO;

// These exercises must be done with Visual Studio

class MainClass {
  public static void Main (string[] args) {
     var path = @"C:\Users\Kiron Roy MD\Desktop\helloWorld.txt";
     var content = File.ReadAllText(path);
     Console.Write(content);

// copy files

     File.Copy(@"C:\Users\Rita Roy MD\Desktop\helloWorld.txt", @"C:\Users\Rita Roy MD\Documents\helloTwo.txt", true);

// copy directory
     Directory.CreateDirectory(@"C: \Users\Rita Roy MD\Desktop\stuff");

// print out files 
    var stuffFiles = Directory.GetFiles(@"C: \Users\Rita Roy MD\Desktop\stuff", "*.*", SearchOption.AllDirectories);
        foreach (var file in stuffFiles)
        Console.WriteLine(file);
// print out all directories

 var directories = Directory.GetDirectories(@"C: \Users\Rita Roy MD\Desktop\stuff", "*.*", SearchOption.AllDirectories);
      foreach (var directory in directories)
      Console.WriteLine(directory);

// largest word in a text file

 var fileText = File.ReadAllText(@"C:\Users\Rita Roy MD\Desktop\helloWorld.txt");
var stringOfWords = fileText.Split(' ');

Console.WriteLine("Text in file: " + fileText);
Console.WriteLine("Words in text: " + fileText.Split(' ').Length);

var finalValue = stringOfWords.OrderByDescending(n => n.Length).First();

Console.WriteLine("Largest word is: " + finalValue);



  }
}