Exemple #1
0
        public static string GetCurrentDirectory(bool expandTilde = false)
        {
            var home    = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile).ToLowerInvariant();
            var current = ShellUtility.GetProperDirectoryCapitalization(Directory.GetCurrentDirectory());

            return(!expandTilde && current.ToLowerInvariant().StartsWith(home)
                       ? $"~{current.Substring( home.Length )}"
                       : current);
        }
Exemple #2
0
        public static string ProcessTilde(string path)
        {
            if (!path.StartsWith("~"))
            {
                return(ShellUtility.GetProperDirectoryCapitalization(path));
            }

            var home         = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            var withoutTilde = path.Substring(1)
                               .Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar)
                               .Trim(Path.DirectorySeparatorChar)
                               .Split(
                new[] { Path.DirectorySeparatorChar },
                StringSplitOptions.RemoveEmptyEntries
                );

            var newPath = Path.Combine(withoutTilde.Prepend(home).ToArray());

            return(ShellUtility.GetProperDirectoryCapitalization(newPath));
        }
Exemple #3
0
        public static string GetProperFilePathCapitalization(string fileName)
        {
            try
            {
                if (!File.Exists(fileName))
                {
                    return(fileName);
                }

                var fileInfo = new FileInfo(fileName);
                var dirInfo  = fileInfo.Directory;

                return(dirInfo is null
                           ? fileInfo.FullName
                           : Path.Combine(
                           ShellUtility.GetProperDirectoryCapitalization(dirInfo.FullName),
                           dirInfo.GetFiles(fileInfo.Name)[0].Name
                           ));
            }
            catch
            {
                return(fileName);
            }
        }
Exemple #4
0
        public static string GetProperDirectoryCapitalization(string dir)
        {
            try
            {
                if (!Directory.Exists(dir))
                {
                    return(dir);
                }

                var dirInfo       = new DirectoryInfo(dir);
                var parentDirInfo = dirInfo.Parent;

                return(parentDirInfo is null
                           ? dirInfo.Name
                           : Path.Combine(
                           ShellUtility.GetProperDirectoryCapitalization(parentDirInfo.FullName),
                           parentDirInfo.GetDirectories(dirInfo.Name)[0].Name
                           ));
            }
            catch
            {
                return(dir);
            }
        }