zorg2000k Posted June 18, 2007 Share Posted June 18, 2007 Hi,Not sure if this is the best section in this forum for help. Here's hoping Looking for some help in scripting a batch file to do the following.I have a dir full of folders that contain lots of txt files. The naming conversion for the txt files are all different.The txt file contents look like this :DAMREM004202FOUSAF0000022CRDCRR000010P1What I want the batch file to do is look for say "DAMREM004202" and update all the txt files that contain that reference to say "DAMREM004203"This is an application stack that we use with OSD to deploy applications. Problem we have found is when it comes to update the software to a new version we will have to update all txt files so the new software version is used if we need to rebuild the machine from OSD.Thanks for you help in advanceZorg Link to comment Share on other sites More sharing options...
IcemanND Posted June 18, 2007 Share Posted June 18, 2007 so you want a way to rename a folder of text files to the first line contained in the text file?how about a vbscript to do that:Const ForReading = 1Set objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.OpenTextFile("C:\Scripts\Log.txt", ForReading)strCharacters = objFile.ReadlineobjFile.ClosestrNewName = "C:\Scripts\" & strCharacters & ".txt"objFSO.MoveFile "C:\Scripts\Log.txt", strNewName Link to comment Share on other sites More sharing options...
nmX.Memnoch Posted June 19, 2007 Share Posted June 19, 2007 If I correctly understand what you're asking, your best bet is to get a utility such as Search and Replace. I can do it with KiXtart (which means it can probably be done in VBS as well, I just don't code VBS)...but Search and Replace will do exactly what you want (again, assuming I correctly understand your question). Link to comment Share on other sites More sharing options...
zorg2000k Posted June 19, 2007 Author Share Posted June 19, 2007 so you want a way to rename a folder of text files to the first line contained in the text file?how about a vbscript to do that:Const ForReading = 1Set objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.OpenTextFile("C:\Scripts\Log.txt", ForReading)strCharacters = objFile.ReadlineobjFile.ClosestrNewName = "C:\Scripts\" & strCharacters & ".txt"objFSO.MoveFile "C:\Scripts\Log.txt", strNewNameThanks for the reply,What I am looking for is a script that will search through all *.txt files in c:\ for a txt value within the .txt file and replace it with another text value.Something like this.Within the follow 1-3.txt files I want to search and replace say "DAMREM004202" to "DAMREM004203"1.txtDAMREM004202FOUSAF0000022CRDCRR000010P12.txtDAMREM004202POLLH00005502CRDCRR000010P13.txtDAMREM004202DRTCA0000022CRDCRR000010P1Hpe this helps.Zorg Link to comment Share on other sites More sharing options...
Yzöwl Posted June 19, 2007 Share Posted June 19, 2007 All you need is a simple search and replace utility. Although this can be done using scripting, there are already some fantastic tools out there for this type of task. My suggestion would be to use rpl.exe.Download the zip binary package, place the exe from the bin directory somewhere within your %path%. Within your console navigate to C: and run the following line of code:rpl -R -q -x .txt DAMREM004202 DAMREM004203 * Link to comment Share on other sites More sharing options...
riso Posted June 19, 2007 Share Posted June 19, 2007 All you need is a simple search and replace utility. Although this can be done using scripting, there are already some fantastic tools out there for this type of task. My suggestion would be to use rpl.exe.Download the zip binary package, place the exe from the bin directory somewhere within your %path%. Within your console navigate to C: and run the following line of code:Location=Inputbox("Please type the location of the file you wish to run below, then press OK.", "Runas")If IsEmpty(Location) ThenWscript.QuitEnd IfConfirm=MsgBox("You entered the following location:" & vbCrLf & vbCrLf & Location & vbCrLf & vbCrLf & "Click ok to make the changes.", vbOkCancel+vbInformation, "Runas")If Confirm=vbOk ThenDim oShell set oShell= Wscript.CreateObject("WScript.Shell")oShell.Run "rpl -R -q -x .txt DAMREM004202 DAMREM004203 " & LocationWscript.QuitElse Confirm=vbCancelWscript.QuitEnd IfThis should work, but may need to be played around with a little as i didnt have time to check it thoroughly. Link to comment Share on other sites More sharing options...
Yzöwl Posted June 19, 2007 Share Posted June 19, 2007 In addition to that line of code you could add the following, which is part of a script i created to to run programs as an admin:From the information we were supplied, I can see no reason why the task would be performed by anyone other than an administrator and there shouldn't even be a need to use a script to deploy the command.However I'm sure your addition may be useful to those capable of breaking down your code for other tasks.<Edit>BTW, the 'wildcard' asterisk at the end of my line of code was a requirement!</Edit> Link to comment Share on other sites More sharing options...
riso Posted June 19, 2007 Share Posted June 19, 2007 In addition to that line of code you could add the following, which is part of a script i created to to run programs as an admin:From the information we were supplied, I can see no reason why the task would be performed by anyone other than an administrator and there shouldn't even be a need to use a script to deploy the command.However I'm sure your addition may be useful to those capable of breaking down your code for other tasks.<Edit>BTW, the 'wildcard' asterisk at the end of my line of code was a requirement!</Edit>It was snippet of code and not the full runas code. The snippet would allow him to enter the old information and the information to be replaced with and then click ok. Then when he clicks ok, the information he entered would be placed after the run code for the file and then the file would run with the information he entered.I hope this makes sence? But basically, this code "should" work, but may need a little "tweaking" in places. Link to comment Share on other sites More sharing options...
zorg2000k Posted June 19, 2007 Author Share Posted June 19, 2007 All you need is a simple search and replace utility. Although this can be done using scripting, there are already some fantastic tools out there for this type of task. My suggestion would be to use rpl.exe.Download the zip binary package, place the exe from the bin directory somewhere within your %path%. Within your console navigate to C: and run the following line of code:rpl -R -q -x .txt DAMREM004202 DAMREM004203 *Works a treat thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now