Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regularizing a file path in C#

Tags:

c#

file

path

Is there a convenient function to regularize a file path in c#?

I have a command-line program which accepts a file path from the user. If they are being too clever, they might supply something like "c:\\mypath", which c# represents internally as "c:\\\\mypath"

I'd like to process the paths so they are regularized to "c:\\mypath"

I could use a string replace where I replace "\\\\" with "\\", but is there a more elegant platform independent way?


1 Answers

use Path. it will handle it for you and will provide you all the functionality you want.

like image 71
DarthVader Avatar answered May 20 '26 05:05

DarthVader



Donate For Us

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