Reputation: 61
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();
}
}
}
Upvotes: 0
Views: 87
Reputation: 6078
[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);
Upvotes: 2