using System.Text.RegularExpressions;
public string CurrentPath { get; private set; }
public Path Cd(string newPath)
var lastOccurance = this.CurrentPath.LastIndexOf('/');
var req = this.CurrentPath.Substring(0,(lastOccurance+1));
return new Path(req + newPath.Substring(3));
public static void Main(string[] args)
private static void ChangeDirectory()
Console.WriteLine("Enter the directory path");
string inputPath = Console.ReadLine();
bool match = Regex.IsMatch(inputPath, @"^[a-zA-Z/]+$");
Console.WriteLine("Sorry, Directory names consist only of English alphabet letters (A-Z and a-z)");
Path path = new Path(inputPath);
Console.WriteLine("Enter the change directory path");
string changePath = Console.ReadLine();
while(!ValidateRequestedPath(changePath))
changePath = Console.ReadLine();
Console.WriteLine(path.Cd(changePath).CurrentPath);
private static bool ValidateRequestedPath(string input)
if(!input.StartsWith(".."))
Console.WriteLine("Change directory should starts with ..");