[英]How can I find tesseract.exe path with C#?
如何找到 tesseract.exe 的路径?
我试过这个,但没有找到,我之前成功地将它用于 python.exe:
var path = Environment.GetEnvironmentVariable("PATH");
string myPath = null;
foreach (var p in path.Split(new char[] { ';' }))
{
var fullPath = Path.Combine(p, "tesseract.exe");
if (File.Exists(fullPath))
{
myPath = fullPath;
break;
}
}
if (myPath != null)
{
Console.WriteLine(myPath);
}
else
{
throw new Exception("Couldn't find myPath on %PATH%");
}
所以我尝试了:
var allExePaths =
from drive in Environment.GetLogicalDrives()
from exePath in Directory.GetFiles(drive, "*.exe", SearchOption.AllDirectories)
select exePath;
但它会引发错误:拒绝访问路径“C:\Documents and Settings”
public static string GetFullPath(string fileName)
{
if (File.Exists(fileName))
return Path.GetFullPath(fileName);
var values = Environment.GetEnvironmentVariable("PATH");
foreach (var path in values.Split(Path.PathSeparator))
{
var fullPath = Path.Combine(path, fileName);
if (File.Exists(fullPath))
return fullPath;
}
return null;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.