Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get temp path with scape characters

How can I get the path from Path.GetTempPath() in a format like this:

C:\\Users\\m3\\AppData\\Local\\Temp\\

Not like this:

C:\Users\m3\AppData\Local\Temp\

I mean I want it with \ scape characters. Is there an automatic way? Or do I have to add \ characters myself?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I need to write the path to a file and the \ characters have to be \\.

>Solution :

A simple way to double the separator char in a path is the following

var psep = Path.DirectorySeparatorChar;
var p = Path.GetTempPath().Replace($"{psep}", $"{psep}{psep}");
Console.WriteLine(p);  
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading