Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace LogBook
- {
- class Program
- {
- static void Main(string[] args)
- {
- string pathWay = @"C:\Users\ARTICUNO\Desktop\Data.txt";
- string action = "";
- bool close = false;
- do
- {
- if (File.Exists(pathWay))
- {
- do
- {
- Console.Clear();
- Console.Write("Found file!\nDo you wish to log something or read a log (read/log/clear/comments/close): ");
- action = Console.ReadLine().ToLower();
- } while (action.ToLower() != "log" && action.ToLower() != "read" && action.ToLower() != "close" && action.ToLower() != "clear" && action.ToLower() != "comments");
- if (action == "log")
- {
- string filename, filedesc;
- Console.Write("Enter file name: ");
- filename = Console.ReadLine().ToLower();
- Console.Write("Enter description (like what you've changed): ");
- filedesc = Console.ReadLine().ToLower();
- using (StreamWriter text = File.AppendText(pathWay))
- {
- text.WriteLine(filename + ", " + DateTime.Today + ", " + filedesc);
- }
- }
- else if (action == "read")
- {
- string filename;
- Console.Write("Enter file name (enter * if you wish to read all): ");
- filename = Console.ReadLine().ToLower();
- if (filename != "*")
- {
- using (StreamReader text = File.OpenText(pathWay))
- {
- string tt;
- while ((tt = text.ReadLine()) != null)
- {
- if (tt.ToLower().StartsWith(filename) && !tt.StartsWith("//"))
- {
- Console.WriteLine(tt);
- }
- }
- }
- Console.ReadLine();
- }
- else
- {
- using (StreamReader text = File.OpenText(pathWay))
- {
- string tt;
- while ((tt = text.ReadLine()) != null)
- {
- if (!tt.StartsWith("//"))
- {
- Console.WriteLine(tt);
- }
- }
- }
- Console.ReadLine();
- }
- } else if (action == "clear")
- {
- string filename;
- Console.Write("Enter file name (enter * if you wish to read all): ");
- filename = Console.ReadLine().ToLower();
- if (filename != "*")
- {
- string testing = "";
- using (StreamReader text = File.OpenText(pathWay))
- {
- string tt;
- while ((tt = text.ReadLine()) != null)
- {
- if (!tt.ToLower().StartsWith(filename))
- {
- testing += "\n" + tt;
- }
- }
- }
- using (StreamWriter text = File.CreateText(pathWay))
- {
- text.WriteLine(testing);
- }
- } else
- {
- using (StreamWriter text = File.CreateText(pathWay))
- {
- text.WriteLine("//Lines that start with '//' will be ignored");
- }
- }
- } else if (action == "comments")
- {
- using (StreamReader text = File.OpenText(pathWay))
- {
- string tt;
- while ((tt = text.ReadLine()) != null)
- {
- if (tt.StartsWith("//"))
- {
- Console.WriteLine(tt);
- }
- }
- }
- Console.ReadLine();
- }
- }
- else
- {
- Console.WriteLine("There is no file currently, so we're making you a new one!\nPlease restart your application.");
- using (StreamWriter text = File.CreateText(pathWay))
- {
- text.WriteLine("//Lines that start with '//' will be ignored");
- text.WriteLine("File creation: " + DateTime.Today);
- }
- Console.ReadLine();
- close = true;
- }
- } while (action != "close" && !close);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement