This is very common thing but i am very confused to get around this.
Taking file path as command line argument in c#.
If i give input "F:\\" then this works perfect.
But when i give input "F:\" it gives output like F:".
I know this is because of backslash escape character.
But my problem is how to get around this without modifying user input because logically user input is correct.
Is it possible without modifying user input get correct path in this situation?
I also know that there is @ character which can be used.
But as i said this is command line argument so the string is already in variable.
I also read some blogs but still i remain unable to resolve my problem.
C# Command-Line Parsing of Quoted Paths and Avoiding Escape Characters
EDIT :Actually my program is to list all the files inside directory so i am first checking for Directory.Exists(command line arguments) and then getting list of all the files if directory exist.
Ok so in that case when user gives Command line argument as i shown above logically the drive exist but just because of escape character it returns false.
Just think about printing the command line argument as follow.
class Program
{
static void Main(string[] args)
{
Console.WriteLine("{0}", args[0]);
Console.Read();
}
}
I am having very less knowledge of c# thanks for helping.