我该如何访问我的目录

时间:2013-03-04 22:11:00

标签: c#

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

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();
     }
  }
}

2 个答案:

答案 0 :(得分:2)

  

[0]“C:\ Users \ soft \ Documents \ Visual”string
          [1]“工作室”字符串
          [2]“2010 \ Projects \ erereerer \ erereerer \ bin \ Debug \ MAXee \”string

它告诉我你没有引号传递参数。

以这种方式打电话给你:

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

或者只是做Blachshma说的话:

directoryPath = String.Join(" ", args);

答案 1 :(得分:0)

用引号传递目录:

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

Join 代码中的args

directoryPath = String.Join(" ", args);