Batch modify TXT records with ( at pos 23

November 10, 2009 at 14:04:46
Specs: Windows XP
Hi again,

I need to append FLIGHT\ at the front of all records that have ( in position 23 in a TXT file.

Help for a BAT file would be greatly appreciated.

EDIT: Added use of BAT file to request.

See More: Batch modify TXT records with ( at pos 23

Report •

November 10, 2009 at 15:50:21
The easiest way I can think to accomplish what you want is to use a VBScript, if you can run a batch file you can run a VBScript. All you have to do is copy the following, the same way you would do a batch file, except the file extension instead of being .bat will be .vbs Then the only change you will have to make is on the first line telling the script where your test file is.

strFileName = "c:\text.txt"

Set objFS = CreateObject("Scripting.FileSystemObject")
StrContents = Split(objFS.OpenTextFile(strFileName).ReadAll, vbNewLine)
Set objTS = objFS.OpenTextFile(strFileName, 2)
For Each strLine In StrContents
If (Mid(strLine,23,1) = "(") Then
objTS.WriteLine "FLIGHT\" & strLine
objTS.WriteLine strLine
End If

Report •

November 10, 2009 at 15:58:27
Thanks gtaion, it's great.

My first reaction was to stick to BATCH files, but this is totally transparent to the end-users.

Report •

November 10, 2009 at 19:52:30
I used to be big into batch files, but it is so nice to have transparency. Instead of hard-coding the location of the file to be modified you can also use an Input box to prompt for the location. like the following:

strFileName = inputbox("Text to Prompt","Title","Default Value")

Report •

Related Solutions

Ask Question