Im not sure why your having a problem here. In M$ Windows, a directory can be specified with or without a back-slash so all of these are correct: c:
and c:\
and c:\media
and c:\media\
. This is the same for Directory.Exists(path)
and other functions like Directory.GetFiles(path)
.
Ths following is a very simple app to list directory files and in my environment it works regardless of whether I put a slash on the end. So c:\media\
gives me all my media files.
class Program
{
static void Main(string[] args)
{
string path = args[0];
Console.WriteLine("trying path: " + path);
if (Directory.Exists(path))
Directory.GetFiles(path).ToList().ForEach(s => Console.WriteLine(s));
else
Console.WriteLine("path not found");
}
}
One thing to note is that in visual studio, when using the debugger such as Quick Watch, it will show the escape character with backslashs. So if user enters c:\media\
the string will be stored as c:\media\
but when you quick watch the path in VS you'll see c:\\media\\
; look deeper with the Text Visualisation feature and you'll see the path correctly shown as c:\media\
.