简体   繁体   中英

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]; , 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
[1] "Studio" string
[2] "2010\\Projects\\erereerer\\erereerer\\bin\\Debug\\MAXee\\" string

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:

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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