Articles

Solved Batch Program to add a \ to each \

November 18, 2012 at 23:19:40
Specs: Windows 7

C:\Users\Daven\Desktop\Nature\_MG_3084.jpg
C:\Users\Daven\Desktop\Nature\_MG_3899.jpg
C:\Users\Daven\Desktop\Nature\_MG_3926.jpg

How do I write a batch script to go through each line and add \ to each \ and write the path with the double \\ in a new text file

so it will look like this:
C:\\Users\\Daven\\Desktop\\Nature\\_MG_3084.jpg
C:\\Users\\Daven\\Desktop\Nature\\_MG_3899.jpg
C:\\Users\\Daven\\Desktop\Nature\\_MG_3926.jpg


See More: Batch Program to add a \ to each \

Report •


#1
November 18, 2012 at 23:45:28
✔ Best Answer

:: ===== script starts here ===============
::
:: ddplus.bat 2012-11-19 14:39:56.53
@echo off > newfile & setLocal enableDELAYedeXpansioN

for /f "tokens=* delims= " %%a in (myfile) do (
set S=%%a
set S=!S:\=\\!
echo.!S!
) >> newfile
::====== script ends here =================

==============================
M2 http://golden-triangle.com


Report •

#2
November 19, 2012 at 10:57:01

what does the ! ! do in batch programming?

Report •

#3
November 19, 2012 at 17:16:25

enableDELAYedeXpansioN
allows the use of ! instead of % for variables. This enables two very convenient features: variable evaluation inside a code-block (for-loop usually), and inserting one variable's value into another variable's name. f/e:
set y=1
set z%y%=ok
echo z%y% is: !z%y%!

see/type: set /? (3rd screen) for a better explanation.


Report •

Related Solutions


Ask Question