using System;
using System.Collections.Generic;
using System.Security.Cryptography;

class FileSystemObject
{
    public string Name { get; set; }
    public FileSystemObject Parent { get; set; }
    public List<FileSystemObject> Children { get; set; }
    public bool IsDirectory { get; set; }

    public FileSystemObject(string name, bool isDirectory)
    {
        Name = name;
        IsDirectory = isDirectory;
        Children = new List<FileSystemObject>();
    }

    public void MoveTo(FileSystemObject newParent)
    {
        if (IsDirectory)
        {
            Parent = newParent;
        }
    }

    public void Show()
    {
        if (IsDirectory)
        {
            Console.WriteLine("/" + Name);
        }
        else
        {
            Console.WriteLine("/~" + Name + "~");
        }
    }

    public void Delete()
    {
        if (IsDirectory && Children.Count > 0)
        {
            Console.Write("Vai tiešām vēlaties dzēst mapi '" + Name + "' ar bērniem? (j/n): ");
            var response = Console.ReadLine();
            if (response?.ToLower() == "j")
            {
                Parent.Children.Remove(this);
                Console.WriteLine("Mape '" + Name + "' ir izdzēsta.");
            }
            else
            {
                Console.WriteLine("Dzēšana atcelta.");
            }
        }
        else
        {
            Parent.Children.Remove(this);
            Console.WriteLine("Objekts '" + Name + "' ir izdzēsts.");
        }
    }

    public void CreateChild(FileSystemObject child)
    {
        if (child != null && !Children.Exists(c => c.Name.Equals(child.Name, StringComparison.OrdinalIgnoreCase)))
        {
            child.Parent = this;
            Children.Add(child);
            Console.WriteLine("Objekts '" + child.Name + "' ir izveidots.");
        }
        else
        {
            Console.WriteLine("Objekts ar nosaukumu '" + child.Name + "' jau pastāv.");
        }
    }
}

class FileSystem
{
    private FileSystemObject currentDirectory;

    public FileSystem()
    {
        currentDirectory = new FileSystemObject("c:", true);
    }

    public void Run()
    {
        while (true)
        {
            Console.Write(currentDirectory.Name + " /> ");
            var input = Console.ReadLine();
            if (input == null) continue;

            var command = input.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
            switch (command[0].ToLower())
            {
                case "mkdir": // Izveido jaunu mapi
                    if (command.Length > 1)
                    {
                        var newDir = new FileSystemObject(command[1], true);
                        currentDirectory.CreateChild(newDir);
                    }
                    break;

                case "create": // Izveido jaunu mapi
                    if (command.Length > 1)
                    {
                        var newFile = new FileSystemObject(command[1], false);
                        currentDirectory.CreateChild(newFile);
                    }
                    break;

                case "rem": // Dzēš mapi vai datni
                    if (command.Length > 1)
                    {
                        var objToDelete = currentDirectory.Children.Find(c => c.Name.Equals(command[1], StringComparison.OrdinalIgnoreCase));
                        if (objToDelete != null)
                        {
                            objToDelete.Delete();
                        }
                        else
                        {
                            Console.WriteLine("Objekts ar nosaukumu '" + command[1] + "' netika atrasts.");
                        }
                    }
                    break;

                case "dir": // Parāda bērnus(mapes un datnes) pašreizējā direktorijā
                    foreach (var child in currentDirectory.Children)
                    {
                        child.Show();
                    }
                    break;

                case "cd": // Pārvietojas uz norādīto mapi
                    if (command.Length > 1)
                    {
                        var dirToChange = currentDirectory.Children.Find(c => c.Name.Equals(command[1], StringComparison.OrdinalIgnoreCase) && c.IsDirectory);
                        if (dirToChange != null)
                        {
                            currentDirectory = dirToChange;
                        }
                        else
                        {
                            Console.WriteLine("Mape ar nosaukumu '" + command[1] + "' netika atrasta.");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Lūdzu, norādiet mapi.");
                    }
                    break;

                case "cd..": //parvietojas uz noradito mapi
                    if (currentDirectory.Parent != null)
                    {
                        currentDirectory = currentDirectory.Parent;
                    }
                    break;

                case "edit": // maina datnes nosaukumu
                    if (command.Length > 1)
                    {
                        var fileToEdit = currentDirectory.Children.Find(c => c.Name.Equals(command[1], StringComparison.OrdinalIgnoreCase) && !c.IsDirectory);
                        if (fileToEdit != null)
                        {
                            Console.WriteLine("Datne: " + fileToEdit.Name);
                        }
                        else
                        {
                            Console.WriteLine("Datne ar nosaukumu '" + command[1] + "' netika atrasta.");
                        }
                    }
                    break;

                case "exit":
                case "by":
                    return;

                default:
                    Console.WriteLine("Nepazīstama komanda.");
                    break;
            }
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        FileSystem fileSystem = new FileSystem();
        fileSystem.Run();
    }
}