Question

I'm currently trying to read a directory and put files with escaping backslashes from the path.

Here is a part of the code :

for /r "Pictures" %%a in (*) do (
set var=%%a
echo %var:\=\\% >> pic.txt
)

I have \=\\ in pic.txt but I want H:\\Pictures\\pic1.jpg in the output file.

I saw something similar here but I can't have what I want.

Any idea ?

EDIT :

for /f "delims=" %%x in (pic.txt) do (
set var=%%x
echo %var:\=/% >> pic2.txt
)

I've got \=/ for each ligne. I'm not far of the solution

Was it helpful?

Solution

Your problem is related to Delayed Expansion. Solve it this way:

setlocal EnableDelayedExpansion
for /r "Pictures" %%a in (*) do (
set var=%%a
echo !var:\=\\! >> pic.txt
)

For further explanation, google for "delayed expansion" and/or read the section about it in set /? command.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top