Computing.Net > Forums > Programming > Batch file to edit files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file to edit files

Reply to Message Icon

Name: alytech
Date: August 30, 2008 at 20:32:30 Pacific
OS: 2k, XP
CPU/Ram: 1Gb
Product: IBM
Comment:

Hi, for work im trying to create a batch file that edits 2 files Definfo.dat and Usage.dat in the following manner.

The file definfo.dat contains the following lines

[Curdefs]=20080718.003
[Lastdefs]=20080717.025

I need the batch file to change the value in [Curdefs]=20080718.003 to 20080717.025 as in [Lastdefs]

Also it needs it to check Usage.dat to see if the value 20080718.003 exists and to change it to 20080717.025.

The values shown here are just examples and can change from on PC to another



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: August 31, 2008 at 00:52:37 Pacific
Reply:

" The values shown here are just examples and can change from on PC to another

"


So, to generalize, you need to change the [Curdefs]= value to the [Lastdefs]= value, right?


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: alytech
Date: August 31, 2008 at 04:39:42 Pacific
Reply:

Correct


0

Response Number 3
Name: ghostdog
Date: August 31, 2008 at 05:08:33 Pacific
Reply:

here's a vbscript


Set objFS = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Set objFile = objFS.OpenTextFile("c:\test\test.txt", ForReading, True)
ReadAllTextFile = objFile.ReadAll
arrAll = Split(ReadAllTextFile,vbCrLf)
For i = LBound(arrAll) To UBound(arrAll)
If InStr(arrAll(i),"Lastdefs") > 0 Then
arrLastDef = Split(arrAll(i),"=")
arrCurDef = Split(arrAll(i-1),"=")
arrCurDef(1)=arrLastDef(1)
arrCurDef = Join(arrCurDef,"=")
arrAll(i-1) = arrCurDef
End If
Next
For i = LBound(arrAll) To UBound(arrAll)
WScript.Echo arrAll(i)
Next

save the above as script.vbs and on command line


c:\test> cscript /nologo script.vbs


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file to edit files

using batch to edit html file conte www.computing.net/answers/programming/using-batch-to-edit-html-file-conte/9401.html

Batch to edit a text file www.computing.net/answers/programming/batch-to-edit-a-text-file/15894.html

batch file to edit/copy local file www.computing.net/answers/programming/batch-file-to-editcopy-local-file/18278.html