0

我想访问我的目录的路径,但我不能。我在我的代码中放了一个断点:

string directoryPath = args[0];

当我点击 时args[0];,它向我展示了这张图片:

-       args    {string[3]} string[]
        [0] "C:\\Users\\soft\\Documents\\Visual"    string
        [1] "Studio"    string
        [2] "2010\\Projects\\erereerer\\erereerer\\bin\\Debug\\MAXee\\" string
        directoryPath   null    string
        filesList   null    string[]
        filesListTmp    null    string[]
        opList  null    erereerer.IFileOperation[]

我一直在尝试访问我的目录,但一直失败。我尝试了很多次,但是当我运行我的代码时,它说目录不存在,而目录实际上存在..

这是我的代码:

class Program
{
   static void Main(string[] args)
   {
      string directoryPath = args[0];
      string[] filesList, filesListTmp;
      IFileOperation[] opList = { new FileProcNameAfter10(),
                                  new FileProcEnc(),
                                  new FileProcByExt("jpeg"),
                                  new FileProcByExt("jpg"),
                                  new FileProcByExt("doc"),
                                  new FileProcByExt("pdf"),
                                  new FileProcByExt("djvu")
   };

   if (Directory.Exists(directoryPath))
   {
      filesList = Directory.GetFiles(directoryPath);
      while (true)
      {
         Thread.Sleep(500);
         filesListTmp = Directory.GetFiles(directoryPath);

         foreach (var elem in Enumerable.Except<string>(filesListTmp, filesList))
         {
            Console.WriteLine(elem);

            foreach (var op in opList)
            {
               if (op.Accept(elem)) op.Process(elem);
            }
         }
            filesList = filesListTmp;
            if (Console.KeyAvailable == true && Console.ReadKey(true).Key == ConsoleKey.Escape) break;
       }
    }

    else
    {
       Console.WriteLine("There is no such directory.");
       Console.ReadKey();
     }
  }
}
4

2 回答 2

2

[0] "C:\Users\soft\Documents\Visual" 字符串
[1] "Studio" 字符串
[2] "2010\Projects\erereerer\erereerer\bin\Debug\MAXee\" 字符串

它告诉我您正在传递不带引号的参数。

以这种方式调用您的程序:

MyApp.exe "C:\Users\soft\Documents\Visual Studio 2010\Projects\erereerer\erereerer\bin\Debug\MAXee\"

或者按照 Blachshma 所说的去做:

directoryPath = String.Join(" ", args);
于 2013-03-04T22:16:20.027 回答
0

用引号传递目录:

MyProgram.exe "C:\Users\soft\Documents\Visual Studio 2010\Projects\erereerer\erereerer\bin\Debug\MAXee\"

加入args代码:

directoryPath = String.Join(" ", args);
于 2013-03-04T22:15:43.233 回答