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_x ml RECIPIENT DV="." obj_name="[Sirota MD]" export_dir="F:\Inbox_backu p"
F:\Cypress\Server\export_x ml RECIPIENT DV="." obj_name="[Keller MD]" export_dir="F:\Inbox_backu p"
F:\Cypress\Server\export_x ml RECIPIENT DV="." obj_name="[Varraux]" export_dir="F:\Inbox_backu p"
F:\Cypress\Server\export_x ml RECIPIENT DV="." obj_name="[Sanborn, MD]" export_dir="F:\Inbox_backu p"
and the rename has commands like:
ren F:\Inbox_backup\FHO_PROD_D V1A_recipi ent.xml [Sirota_MD]_%date:~4,2%-%d ate:~7,2%- %date:~10% .xml
ren F:\Inbox_backup\FHO_PROD_D V1A_recipi ent.xml [Keller_MD]_%date:~4,2%-%d ate:~7,2%- %date:~10% .xml
ren F:\Inbox_backup\FHO_PROD_D V1A_recipi ent.xml
[Varraux]_%date:~4,2%-%dat e:~7,2%-%d ate:~10%.x ml
ren F:\Inbox_backup\FHO_PROD_D V1A_recipi ent.xml [Sanborn,_MD]_%date:~4,2%- %date:~7,2 %-%date:~1 0%.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_x ml RECIPIENT DV="." obj_name="[Sirota MD]" export_dir="F:\Inbox_backu p"
ren F:\Inbox_backup\FHO_PROD_D V1A_recipi ent.xml [Sirota_MD]_%date:~4,2%-%d ate:~7,2%- %date:~10% .xml
F:\Cypress\Server\export_x ml RECIPIENT DV="." obj_name="[Keller MD]" export_dir="F:\Inbox_backu p"
ren F:\Inbox_backup\FHO_PROD_D V1A_recipi ent.xml [Keller_MD]_%date:~4,2%-%d ate:~7,2%- %date:~10% .xml
F:\Cypress\Server\export_x ml RECIPIENT DV="." obj_name="[Varraux]" export_dir="F:\Inbox_backu p"
ren F:\Inbox_backup\FHO_PROD_D V1A_recipi ent.xml [Varraux]_%date:~4,2%-%dat e:~7,2%-%d ate:~10%.x ml
F:\Cypress\Server\export_x ml RECIPIENT DV="." obj_name="[Sanborn, MD]" export_dir="F:\Inbox_backu p"
ren F:\Inbox_backup\FHO_PROD_D V1A_recipi ent.xml [Sanborn,_MD]_%date:~4,2%- %date:~7,2 %-%date:~1 0%.xml
The export has commands like:
F:\Cypress\Server\export_x
F:\Cypress\Server\export_x
F:\Cypress\Server\export_x
F:\Cypress\Server\export_x
and the rename has commands like:
ren F:\Inbox_backup\FHO_PROD_D
ren F:\Inbox_backup\FHO_PROD_D
ren F:\Inbox_backup\FHO_PROD_D
[Varraux]_%date:~4,2%-%dat
ren F:\Inbox_backup\FHO_PROD_D
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_x
ren F:\Inbox_backup\FHO_PROD_D
F:\Cypress\Server\export_x
ren F:\Inbox_backup\FHO_PROD_D
F:\Cypress\Server\export_x
ren F:\Inbox_backup\FHO_PROD_D
F:\Cypress\Server\export_x
ren F:\Inbox_backup\FHO_PROD_D
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thank you rortiz77
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.Fi
Set objFile1 = objFileSystem.GetFile(FILE
Set objFile2 = objFileSystem.GetFile(FILE
Set objStream1 = objFile1.OpenAsTextStream(
Set objStream2 = objFile2.OpenAsTextStream(
arrStream1 = Split(objStream1.ReadAll, VbCrLf)
arrStream2 = Split(objStream2.ReadAll, VbCrLf)
Set objFile = objFileSystem.OpenTextFile
If UBound(arrStream1) = UBound(arrStream2) Then
For i = 0 To UBound(arrStream1)
objFile.WriteLine arrStream1(i)
objFile.WriteLine arrStream2(i)
Next
End If