This is the example exercises that I tried.
1. When creating a new text file using
Console.Write("\nPlease input filename : ");
string name = Console.ReadLine();
path += Path.DirectorySeparatorChar+ name + ".txt";
File.Create(path).Close();
// Please bear in mind that you need to close the created process after create a file so that you can edit it later on.
2.When editing a file why would need to type the file name as you can list and choose the file number.
// Listing the existing file codes......
public string choose(string view)
{
Console.WriteLine("Please choose the existing file ");
Console.WriteLine("--------------------------------");
string[] choose= Directory.GetFiles(view);
int i = 0;
foreach (string s in choose)
{ i++;
Console.WriteLine("No {0} : " + s, i);
}
Console.WriteLine("Please enter your selection file : ");
i= int.Parse(Console.ReadLine());
Console.WriteLine(choose[i - 1]);
Console.ReadLine();
return (choose[i - 1]);
}
// Edit code...
public void editFile(string p)
{
string current = File.ReadAllText(p);
Console.WriteLine("Opening file : "+ p);
Console.WriteLine(current);
string answer = "n";
do
{
Console.WriteLine("Please write below your new text : ");
current = Console.ReadLine();
Console.WriteLine("\nAre you sure to save? (y/n)"); ///need improvise /evolution
answer = Console.ReadLine();
} while (answer != "y" );
if (answer == "y")
{
File.WriteAllText(p, current);
Console.WriteLine("Your text have been save.");
}
else Console.WriteLine("Your text have NOT been save.");
Console.ReadLine();
}
* I still haven't found a really good codes to go with the (y/n/q) selection.