Changing a specific character in a text file

Ibm Pc dos 2000 cdrom
March 6, 2010 at 01:43:53
Specs: Windows XP
So I'm searching around the 'ol Interweb looking for a solution to the above problem, and I came across a guy needing to change every instance of "\" to "\\" inside a text file. Here's the answer:

@echo off
if "%1"=="GoTo" goto %2
%comspec% /v:on /c %0 GoTo start
type nul> %temp%.\$
for /F "tokens=*" %%S in (filename.ext) do (
set str=%%S
echo !str:\=\\!>> %temp%.\$
copy/y %temp%.\$ filename.ext > nul
del %temp%.\$

...tested this, and it does work. So my question I have only a novice understanding of how advanced batch files work, so any help with breaking this down would be greatly appreciated.

...and to add to the puzzle (here comes the kicker), supposed I'd like to change the string "ClosePrepFailed=1" to "ClosePrepFailed=0" using the above do-hicky (yeah, I went there). Thanks again :o)

See More: Changing a specific character in a text file

Report •

March 6, 2010 at 23:03:28
CygnusX1, suggestion for you. Most word processors I'm familiar with support the Ctrl+H text replacement command.
Simply hit Ctrl+H and you'll conjure a box asking what to replace and with what. It can deal with individual instances or the whole document. How does it work? Dunno. Pretty well.
Ed in Texas.

Report •

March 7, 2010 at 01:25:49
Oh and Word's find/replace feature go way back. The script above would actually be a small part of a larger batch file that I'm working on which would make copies of folders, rename those copies with the current date, then change that .ini entry from 1 to 0. Actually, I've discovered a nifty little tool called AutoHotKey that "...offers a scripting-language, which is more powerful than every batch-file and easier to learn than the Windows-Scripting-Host." Either way, thanks for the reply. :o)

Report •

Related Solutions

Ask Question