Link to home
Start Free TrialLog in
Avatar of rortiz77
rortiz77

asked on

Merging two DOS commands to make one big batch file

I have two text files.  One called "Export.txt" and another called "Rename.txt"  Eventually I want to join them together to make a big batch file.  

The export has commands like:
F:\Cypress\Server\export_xml RECIPIENT DV="." obj_name="[Sirota MD]" export_dir="F:\Inbox_backup"
F:\Cypress\Server\export_xml RECIPIENT DV="." obj_name="[Keller MD]" export_dir="F:\Inbox_backup"
F:\Cypress\Server\export_xml RECIPIENT DV="." obj_name="[Varraux]" export_dir="F:\Inbox_backup"
F:\Cypress\Server\export_xml RECIPIENT DV="." obj_name="[Sanborn, MD]" export_dir="F:\Inbox_backup"

and the rename has commands like:
ren F:\Inbox_backup\FHO_PROD_DV1A_recipient.xml [Sirota_MD]_%date:~4,2%-%date:~7,2%-%date:~10%.xml
ren F:\Inbox_backup\FHO_PROD_DV1A_recipient.xml [Keller_MD]_%date:~4,2%-%date:~7,2%-%date:~10%.xml
ren F:\Inbox_backup\FHO_PROD_DV1A_recipient.xml
[Varraux]_%date:~4,2%-%date:~7,2%-%date:~10%.xml
ren F:\Inbox_backup\FHO_PROD_DV1A_recipient.xml [Sanborn,_MD]_%date:~4,2%-%date:~7,2%-%date:~10%.xml

The problem is that I have about 1,200 rows of commands for each. To do what I want manually would take forever...there has to be a better way.  The challenge, should you choose to accept, is to get it to look like this after being merged into one file:

F:\Cypress\Server\export_xml RECIPIENT DV="." obj_name="[Sirota MD]" export_dir="F:\Inbox_backup"
ren F:\Inbox_backup\FHO_PROD_DV1A_recipient.xml [Sirota_MD]_%date:~4,2%-%date:~7,2%-%date:~10%.xml

F:\Cypress\Server\export_xml RECIPIENT DV="." obj_name="[Keller MD]" export_dir="F:\Inbox_backup"
ren F:\Inbox_backup\FHO_PROD_DV1A_recipient.xml [Keller_MD]_%date:~4,2%-%date:~7,2%-%date:~10%.xml

F:\Cypress\Server\export_xml RECIPIENT DV="." obj_name="[Varraux]" export_dir="F:\Inbox_backup"
ren F:\Inbox_backup\FHO_PROD_DV1A_recipient.xml [Varraux]_%date:~4,2%-%date:~7,2%-%date:~10%.xml

F:\Cypress\Server\export_xml RECIPIENT DV="." obj_name="[Sanborn, MD]" export_dir="F:\Inbox_backup"
ren F:\Inbox_backup\FHO_PROD_DV1A_recipient.xml [Sanborn,_MD]_%date:~4,2%-%date:~7,2%-%date:~10%.xml

Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image


The files are exactly the same length?

Just for simplicity this only works if they are, I'm sure it can be modified though.


Const FILE_ONE = "<FileOne>"
Const FILE_TWO = "<FileTwo>"
Const OUT_FILE = "<OutputFile>"

Set objFileSystem = CreateObject("Scripting.FileSystemObject")

Set objFile1 = objFileSystem.GetFile(FILE_ONE)
Set objFile2 = objFileSystem.GetFile(FILE_TWO)

Set objStream1 = objFile1.OpenAsTextStream(1, 0)
Set objStream2 = objFile2.OpenAsTextStream(1, 0)

arrStream1 = Split(objStream1.ReadAll, VbCrLf)
arrStream2 = Split(objStream2.ReadAll, VbCrLf)

Set objFile = objFileSystem.OpenTextFile(OUT_FILE, 2, True, 0)

If UBound(arrStream1) = UBound(arrStream2) Then
      For i = 0 To UBound(arrStream1)
            objFile.WriteLine arrStream1(i)
            objFile.WriteLine arrStream2(i)
      Next
End If

Oh yeah, and it's VbScript and needs saving as .vbs before you can run it.
Is it not possible to simply do:

copy C:\Export.txt C:\BigBatchFile.bat
type Rename.txt >> C:\BigBatchFile.bat

Doesn't that just add the contents of the second file onto the end of the first? The lines need to alternate don't they?

Chris
Oh - I wasn't sure...perhaps I just misread it... my apologies.
SOLUTION
Avatar of nelsoncomputer
nelsoncomputer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

It would have made it far too simple :)

Not that it took more than a couple of minutes to knock up a bit of VbScript, I just figured it was a bit beyond my very limited knowledge of DOS scripting.

Chris
Certainly doable with dos scripting... but your script will do the job as well. :^ )
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you rortiz77