簡體   English   中英

我該如何訪問我的目錄

[英]how can i access my directory

我想訪問我的目錄的路徑,但我不能。 我在我的代碼中放了一個斷點:

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

[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);

要么用引號傳遞目錄:

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

或者在代碼中加入 args

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM