本文整理汇总了C#中System.IO.DriveInfo.StartsWith方法的典型用法代码示例。如果您正苦于以下问题:C# DriveInfo.StartsWith方法的具体用法?C# DriveInfo.StartsWith怎么用?C# DriveInfo.StartsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.DriveInfo
的用法示例。
在下文中一共展示了DriveInfo.StartsWith方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetGitPath
private static string GetGitPath()
{
var envPath = Environment.GetEnvironmentVariable("PATH");
if (!string.IsNullOrWhiteSpace(envPath))
{
foreach (var p in envPath.Split(Path.PathSeparator))
{
var path = Path.Combine(p, "git.exe");
if (File.Exists(path))
return path;
}
}
var gitPath = Path.Combine("Git", "bin", "git.exe");
var envProgramFiles = Environment.GetEnvironmentVariable("ProgramFiles");
if (!string.IsNullOrWhiteSpace(envProgramFiles))
{
var path = Path.Combine(envProgramFiles, gitPath);
if (File.Exists(path))
return path;
}
envProgramFiles = Environment.GetEnvironmentVariable("ProgramFiles(x86)");
if (!string.IsNullOrWhiteSpace(envProgramFiles))
{
var path = Path.Combine(envProgramFiles, gitPath);
if (File.Exists(path))
return path;
}
var envSystemDrive = Environment.GetEnvironmentVariable("SystemDrive");
if (string.IsNullOrEmpty(envSystemDrive))
{
throw new Exception("Environment.GetEnvironmentVariable('SystemDrive') returned null!");
}
if (!string.IsNullOrWhiteSpace(envSystemDrive))
{
var path = Path.Combine(envSystemDrive, "Program Files", gitPath);
if (File.Exists(path))
return path;
path = Path.Combine(envSystemDrive, "Program Files (x86)", gitPath);
if (File.Exists(path))
return path;
path = Path.Combine(envSystemDrive, gitPath);
if (File.Exists(path))
return path;
}
try
{
var cRoot = new DriveInfo("C").RootDirectory.FullName;
if (!cRoot.StartsWith(envSystemDrive, StringComparison.OrdinalIgnoreCase))
{
var path = Path.Combine(cRoot, "Program Files", gitPath);
if (File.Exists(path))
return path;
path = Path.Combine(cRoot, "Program Files (x86)", gitPath);
if (File.Exists(path))
return path;
path = Path.Combine(cRoot, gitPath);
if (File.Exists(path))
return path;
}
}
catch (Exception exception)
{
throw new Exception("UpdateAssemblyInfo - GetGitPath: " + exception.Message);
}
Console.WriteLine("WARNING: Might not be able to run Git command line tool!");
return "git";
}