本文整理汇总了C#中System.Management.Path.HasDrive方法的典型用法代码示例。如果您正苦于以下问题:C# Path.HasDrive方法的具体用法?C# Path.HasDrive怎么用?C# Path.HasDrive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.Path
的用法示例。
在下文中一共展示了Path.HasDrive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例2: GetFilesystemExpansions
public IEnumerable<string> GetFilesystemExpansions(string cmdStart, string replacableEnd)
{
replacableEnd = StripQuotes(replacableEnd);
var p = new System.Management.Path(replacableEnd).NormalizeSlashes().ResolveTilde();
var startPath = new System.Management.Path(".");
string lookFor = replacableEnd;
if (p.ToString().Contains(p.CorrectSlash))
{
// we already deal with a path
var escapedSlash = p.CorrectSlash;
if (escapedSlash.Equals(@"\"))
{
escapedSlash = @"\\";
}
if (!p.HasDrive() && !Regex.IsMatch(p, @"^\.+" + escapedSlash))
{
p = new System.Management.Path(".").Combine(p);
}
if (p.EndsWithSlash())
{
startPath = p;
lookFor = "";
}
else
{
startPath = p.GetParentPath(null);
lookFor = p.GetChildNameOrSelfIfNoChild();
}
}
var dirinfo = new DirectoryInfo(startPath);
if (!dirinfo.Exists)
{
return Enumerable.Empty<string>();
}
var expansions = new List<string>();
var pattern = new WildcardPattern(lookFor + "*");
bool allowHidden = lookFor.Length > 0;
// add directories
expansions.AddRange(
from subdir in dirinfo.GetDirectories()
where pattern.IsMatch(subdir.Name) &&
(allowHidden || (subdir.Attributes & FileAttributes.Hidden) == 0)
orderby subdir.Name ascending
select QuoteIfNecessary(startPath.Combine(subdir.Name).AppendSlashAtEnd())
);
// add files
expansions.AddRange(
from file in dirinfo.GetFiles()
where pattern.IsMatch(file.Name) &&
(allowHidden || (file.Attributes & FileAttributes.Hidden) == 0)
orderby file.Name ascending
select QuoteIfNecessary(startPath.Combine(file.Name))
);
return expansions;
}