0

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

Community
  • 1
  • 1
thomas-hiron
  • 928
  • 4
  • 21
  • 40

1 Answers1

3

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.

Aacini
  • 65,180
  • 12
  • 72
  • 108