Skip to content

Instantly share code, notes, and snippets.

@edhebi
Created August 6, 2020 23:33
Show Gist options
  • Save edhebi/c5976a0399b8378def09a774e1672d6c to your computer and use it in GitHub Desktop.
Save edhebi/c5976a0399b8378def09a774e1672d6c to your computer and use it in GitHub Desktop.
using System;
using System.IO;
namespace RealPath
{
class Program
{
static string RealPath(string path)
{
if (!File.Exists(path) && !Directory.Exists(path)) return path;
var infos = new DirectoryInfo(path);
if (infos.Parent is null) return infos.Name.ToUpper();
var basename = infos.Parent.GetFileSystemInfos(infos.Name)[0].Name;
return Path.Combine(RealPath(infos.Parent.FullName), basename);
}
static void Main(string[] args)
{
foreach (string path in args)
{
Console.WriteLine(RealPath(path));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment