2013-03-04 48 views
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(); 
    } 
    } 
} 
+0

你是如何调用你的程序? – cdhowie 2013-03-04 22:12:23

+4

在双引号之间传递参数 – Steve 2013-03-04 22:14:16

+0

@cdhowie即时编译,但它返回的消息当目录实际存在时,没有这样的目录 – thanks 2013-03-04 22:16:33

回答

0

无论是通过目录报价:

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

Joinargs在代码:

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

当我通过双引号即时通讯再次获取此[0] =“C:\\ Users \\ soft \\ Documents \\ Visual Studio 2010 \\ Projects \\ erereerer \\ erereerer \\ bin \\ Debug \\ MAXee \“” – thanks 2013-03-04 22:21:02

+0

但这就是你想要的,不是吗?完整的目录?第二个解决方案有帮助吗? – Blachshma 2013-03-04 22:22:33

+0

但我得到一个消息,该目录不存在,我认为当这是照顾目录将show – thanks 2013-03-04 22:26:21

2

[0] “C:\用户\软\文件\视觉” 的字符串
[1] “工作室” 串
[2]“2010 \项目\ erereerer \ erereerer \ BIN \调试\ MAXee \ “string

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

叫你这样编程:

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

或者只是做Blachshma说:

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

我会反对加入字符串,因为调用程序的人应该首先将路径作为一个参数传递。它最终取决于是否想要记录此特定(错误)功能,并且必须在将来的版本中支持它。 – cdhowie 2013-03-04 22:20:56

+0

@cdhowie当然,我只是展示了所有可能的方法来完成它。 OP必须看到对他/她最好的东西。 – 2013-03-04 22:22:30