user236520
user236520

Reputation:

Regularizing a file path in C#

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?

Upvotes: 3

Views: 530

Answers (2)

Axis
Axis

Reputation: 846

I think you can use @"C:\myPath\"

Upvotes: 0

DarthVader
DarthVader

Reputation: 55022

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

Upvotes: 6

Related Questions