What does this code do in this example, what does args[0] store? If I want to access the path for my directory, but I can not though i'm pretty sure im making a mistake on the same line.
string directoryPath = args[0];
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();
}
}
}
OK, so args[0] represents the first command-line parameter passed to the program - so in short we have no idea what it represents in your case. But consider this command-line:
MyProgram.exe
that would pass nothing into the args[] and therefore there wouldn't be any index of 0. Now consider this command-line:
MyProgram.exe Hello
that would pass Hello into the args[] and therefore the value at index 0 would be Hello. Now let's consider this command-line:
MyProgram.exe Hello World
that would pass Hello and World into the args[] and therefore the value at index 0 would be Hello and the value at index 1 would be World. Now, another thing to remember is to " parameters, especially when necessarily dealing with paths:
MyProgram.exe "C:\MyPath\ToSomewhere"
what does args 0 store in this program
Its command line parameter, you get value in it if you execute your exe from command line with parameters.
For debugging purpose you can send it through visual studio as well, go to project properties, Debug and under start option specify.

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With