【发布时间】:2017-03-16 18:18:32
【问题描述】:
我正在开发一个 C# 锐利的控制台应用程序。我遇到了以下与相对路径相关的错误,我尝试将调试设置从 anyCPU 更改为 x86,但这不起作用。有人可以指出我正确的方向。谢谢
public static void ReadOrders(string pOrderDirectory)
{
// This exception is already thrown by <code>Directory.GetFiles()</code> but caught earlier here to allow
// the option of throwing an app-specific exception
if (!Directory.Exists(pOrderDirectory))
{
throw new DirectoryNotFoundException("Unable to find input directory for orders: " + pOrderDirectory); //ran into the exception here.
}
// Process the list of files found in the directory.
string[] oOrderFilenames = Directory.GetFiles(pOrderDirectory, SalesTaxHelper.GetConfigurationValue(CONFIG_KEY_FILE_SEARCH_PATTERN));
if (oOrderFilenames.Length < 1)
{
throw new IOException("No orders found in input directory");
}
foreach (var oOrderFile in oOrderFilenames)
{
var oOrderProcessor = new Order();
var oOrderLineItems = File.ReadAllLines(oOrderFile);
foreach (var oLineItem in oOrderLineItems)
{
oOrderProcessor.AddLineItem(oLineItem);
}
Console.WriteLine(oOrderProcessor.PrintInvoice());
}
Console.WriteLine("======================================");
Console.WriteLine("PROCESSED ALL INPUT FILES IN DIRECTORY");
}
异常:找不到订单的输入目录:
谢谢, 哈里
【问题讨论】:
-
可能与权限和访问该位置有关?
-
目录是否存在?传递给函数的
pOrderDirectory的值是多少? -
pOrderDirectory 的值必须用一个包含 3 个文本文件的输入文件夹填充,目前它没有读取它们
-
@Hari 但
pOrderDirectory实际上是什么样子的?它是完全合格的有效路径吗,例如“C:\用户\哈里\输入\文件夹?” ...或“/stuff/here/”或完全不同的东西?异常告诉您它找不到您指定的路径。确保您指定的路径是函数的正确格式。 -
我希望它看起来像“/input”,但是它没有填充任何东西