Escape Path in Bat file

batch-file, path, windows

Solution

I'd recommend replacing `\` with `\\`:

@echo off
echo %CD:\=\\% > path.txt
echo Done!

I found this (and plenty of other ways of manipulating strings in batch files) here: http://www.dostips.com/DtTipsStringManipulation.php

Problem

I need to escape and write the current directory folder path in .Bat file. Below is the code I use. ``` @echo off echo %CD% > path.txt echo Done! ``` It outputs below path: ``` C:\Users\Polo\Desktop\New folder ``` I need to write it escaped as below: ``` C:\\Users\\Polo\\Desktop\\New folder ``` How can I achieve this?

Original source