当前位置: 首页>>代码示例>>C#>>正文


C# Path.GetDrive方法代码示例

本文整理汇总了C#中System.Management.Path.GetDrive方法的典型用法代码示例。如果您正苦于以下问题:C# Path.GetDrive方法的具体用法?C# Path.GetDrive怎么用?C# Path.GetDrive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.Path的用法示例。


在下文中一共展示了Path.GetDrive方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CalculateFullPath

        public static Path CalculateFullPath(Path currentLocation, Path changeCommand)
        {
            changeCommand = (changeCommand ?? string.Empty).NormalizeSlashes();
            currentLocation = currentLocation.NormalizeSlashes();

            bool applyParts = false;
            Path resultPath;

            // use the input 'changeCommand' path if it's
            // 'rooted' otherwise we go from the currentLocation
            if (changeCommand.HasDrive())
            {
                // windows case where changeCommand == "/" or "\" but the currentLocation has a "C:" drive
                string currentLocationDrive = currentLocation.GetDrive();
                if (changeCommand.StartsWithSlash() && !changeCommand.GetDrive().Equals(currentLocationDrive, StringComparison.InvariantCultureIgnoreCase))
                {
                    resultPath = new Path(currentLocation.CorrectSlash, currentLocation.WrongSlash, string.Format("{0}:{1}", currentLocationDrive, changeCommand));
                }
                else
                {
                    resultPath = changeCommand;
                }
            }
            else
            {
                applyParts = true;
                resultPath = currentLocation;
            }

            var correctSeparator = Char.Parse(currentLocation.CorrectSlash);
            var changeParts = changeCommand.ToString().Split(correctSeparator).Where(s => !string.IsNullOrEmpty(s));

            foreach (var part in changeParts)
            {
                // ignore single dot as it does nothing...
                if (part == ".")
                {
                    continue;
                }

                // ignore trying to go up a dir from the root dir
                if (part == ".." && resultPath.IsRootPath())
                {
                    continue;
                }

                if (part == "..")
                {
                    resultPath = resultPath.GetParentPath(currentLocation.GetDrive());
                }
                else if (applyParts)
                {
                    resultPath = resultPath.Combine(part);
                }
            }

            return resultPath.ApplyDriveSlash();
        }
开发者ID:b333z,项目名称:Pash,代码行数:58,代码来源:PathNavigation.cs

示例2: GetDrive

 private PSDriveInfo GetDrive(Path path)
 {
     string driveName = path.GetDrive();
     if (!string.IsNullOrEmpty(driveName))
     {
         return _executionContext.SessionState.Drive.Get(driveName);
     }
     return null;
 }
开发者ID:,项目名称:,代码行数:9,代码来源:

示例3: GetDriveOrThrow

 private Path GetDriveOrThrow(Path path)
 {
     string drive = path.GetDrive();
     if (drive != null)
     {
         return drive + ":";
     }
     throw new FormatException(string.Format("Cannot parse path because path '{0}' does not have a qualifier specified.", path));
 }
开发者ID:mauve,项目名称:Pash,代码行数:9,代码来源:SplitPathCommand.cs

示例4: GetProviderByPath

        private CmdletProvider GetProviderByPath(Path path)
        {
            // MUST: implement for "dir"
            if (string.IsNullOrEmpty(path))
                path = CurrentLocation.Path;

            string driveName = path.GetDrive();
            PSDriveInfo drive = GetDrive(driveName);

            if (drive == null)
            {
                drive = CurrentLocation.Drive;
            }

            if (drive == null)
                return null;

            return GetProviderInstance(drive.Provider.Name);
        }
开发者ID:b333z,项目名称:Pash,代码行数:19,代码来源:SessionStateGlobal.cs


注:本文中的System.Management.Path.GetDrive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。