Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys.

I have currently a little Problem, because the System doesn't recognizes a Path that ends with a backslash

I'm trying this here, but it has no affect on the argument
C#
args[0] = args[0].TrimEnd(Path.DirectorySeparatorChar);


thanks.

Sincerely:
Jonas
Posted
Comments
PIEBALDconsult 8-Feb-15 11:05am    
"the System doesn't recognizes a Path that ends with a backslash"
What? You'll have a hard time convincing me of that, can you provide an example? (Use Improve question.)

1 solution

"the System doesn't recognizes a Path that ends with a backslash"
Yes, it does: It says "this is a folder".
C#
static void Main(string[] args)
    {
    string[] files = Directory.GetFiles(args[0]);
    foreach (string s in files) Console.WriteLine(s);
    args[0] = args[0].TrimEnd(Path.DirectorySeparatorChar);
    foreach (string s in args)
        Console.WriteLine(s);
    }

Then run the app with "ConsoleTester D:\temp\", and it prints the list of files in my temporary folder.

But...Do note that Path.DirectorySeparatorChar is only backslash - it will not match a slash '/' as well, but Windows is happy with either.

And if your path ends with a separator character, it's a folder path, not a file path. So File.RealAllLines (and so forth) will not work - they need a file, not a folder.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900