简体   繁体   English

我该如何访问我的目录

[英]how can i access my directory

I want to access the path for my directory, but I can not. 我想访问我的目录的路径,但我不能。 I put a breakpoint in my code: 我在我的代码中放了一个断点:

string directoryPath = args[0];

And when i clicked on the args[0]; 当我点击args[0]; , it showed me this image: ,它向我展示了这个图像:

-       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[]

I have been trying to access my directory but I have been failing. 我一直试图访问我的目录,但我一直在失败。 I tried so many times but when I run my code its saying directory does not exist while the directory is in fact there.. 我尝试了很多次,但是当我运行我的代码时,它的说法目录不存在,而目录实际上就在那里。

This is my code: 这是我的代码:

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

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

It tells me that you are passing the arguments without quotes. 它告诉我你没有引号传递参数。

Call you program this way: 用这种方式打电话给你:

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

Or just do what Blachshma said: 或者只是做Blachshma说的话:

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

Either pass the directory in quotes: 要么用引号传递目录:

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

or Join the args in code: 或者在代码中加入 args

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM