From: balzer on
two text files, doc1.txt and doc2.txt
document1.txt contains code which have names (absde.exe, etc) inside double
quotes.

ReturnAPP_B ("absde.exe")
ReturnAPP_B ("dhdjd.exe")
ReturnAPP_B ("fhgfjfj.exe")

Document2.txt contains list of files, each from new line
file1.exe
file2.exe
files3.exe
....

The task is just replace all files in doc1.txt inside pattern with files
from doc2.txt , i.e. replace "absde.exe" with "file1.exe", "dhdjd.exe" with
"file2.exe"and so on.
The quantity of files in doc1.txt and doc2.txt is n ot the same, doc1.txt
have more files, so the rest files in doc1.txt can be left as it, without
replacing.
How to make this with VBScript?

Thanks.

From: ekkehard.horner on
balzer schrieb:
> two text files, doc1.txt and doc2.txt
> document1.txt contains code which have names (absde.exe, etc) inside
> double quotes.
>
> ReturnAPP_B ("absde.exe")
> ReturnAPP_B ("dhdjd.exe")
> ReturnAPP_B ("fhgfjfj.exe")
>
> Document2.txt contains list of files, each from new line
> file1.exe
> file2.exe
> files3.exe
> ...
>
> The task is just replace all files in doc1.txt inside pattern with
> files from doc2.txt , i.e. replace "absde.exe" with "file1.exe",
> "dhdjd.exe" with "file2.exe"and so on.
> The quantity of files in doc1.txt and doc2.txt is n ot the same,
> doc1.txt have more files, so the rest files in doc1.txt can be left as
> it, without replacing.
> How to make this with VBScript?
>
> Thanks.
>
I'm not sure that I understand your specs/problem (and your data/formats)
correctly, but to get you started:

Option Explicit

Dim goFS : Set goFS = CreateObject( "Scripting.FileSystemObject" )

WScript.Quit doMain00()

Function doMain00()
doMain00 = 1 ' assume error
Dim reTo : Set reTo = New RegExp
reTo.Global = True
reTo.IgnoreCase = True
reTo.MultiLine = True
reTo.Pattern = "^\w+\.exe"
Dim reFrom : Set reFrom = New RegExp
reFrom.Global = True
reFrom.IgnoreCase = True
reFrom.Pattern = """\w+\.exe"""
Dim sSource : sSource = goFS.OpenTextFile( ".\doc1.txt" ).ReadAll()
WScript.Echo sSource
Dim aRpl : aRpl = getRplTo( reTo, ".\doc2.txt" )
addRplFrom aRpl, reFrom, sSource
WScript.Echo "=====>"
WScript.Echo applyRpl( aRpl, sSource )
doMain00 = 0 ' reached this, so seems ok
End Function

Function getRplTo( reX, sFSpec )
Dim oMTS : Set oMTS = reX.Execute( goFS.OpenTextFile( sFSpec ).ReadAll() )
ReDim aRVal( oMTS.Count - 1, 1 )
Dim nIdx
For nIdx = 0 To UBound( aRVal )
aRVal( nIdx, 1 ) = oMTS( nIdx ).Value
Next
getRplTo = aRVal
End Function

Sub addRplFrom( aRpl, reX, sSource )
Dim oMTS : Set oMTS = reX.Execute( sSource )
Dim nIdx
For nIdx = 0 To UBound( aRpl )
aRpl( nIdx, 0 ) = oMTS( nIdx ).Value
Next
End Sub

Function applyRpl( aRpl, ByVal sSource )
Dim nIdx
For nIdx = 0 To UBound( aRpl )
sSource = Replace( sSource, aRpl( nIdx, 0 ), qq( aRpl( nIdx, 1 ) ) )
Next
applyRpl = sSource
End Function

Function qq( sTxt )
qq = """" & sTxt & """"
End Function

output:

C:\wis\_vbs\0506\dev\forum\balzer
cscript balzer.vbs
contains code which have names (absde.exe, etc) inside double quotes.

ReturnAPP_B ("absde.exe")
ReturnAPP_B ("dhdjd.exe")
ReturnAPP_B ("fhgfjfj.exe")

The quantity of files in doc1.txt and doc2.txt is n ot the same,
doc1.txt have more files, so the rest files in doc1.txt can be left as
it, without replacing.

ReturnAPP_B ("nottobechanged.exe")
ReturnAPP_B ("keepmeto.exe")

But what about a to-be-replaced exe - eg dhdjd.exe - occuring more
than once

ReturnAPP_B ("fhgfjfj.exe")


=====>
contains code which have names (absde.exe, etc) inside double quotes.

ReturnAPP_B ("file1.exe")
ReturnAPP_B ("file2.exe")
ReturnAPP_B ("files3.exe")

The quantity of files in doc1.txt and doc2.txt is n ot the same,
doc1.txt have more files, so the rest files in doc1.txt can be left as
it, without replacing.

ReturnAPP_B ("nottobechanged.exe")
ReturnAPP_B ("keepmeto.exe")

But what about a to-be-replaced exe - eg dhdjd.exe - occuring more
than once

ReturnAPP_B ("files3.exe")


I hope that based on this the discussion of specs (e.g. is it correct
to map the nth occurrence of a To-exe to the nth occurrence of a
From-exe) and implementation details (just ask for explanations)
easier.
From: balzer on

"ekkehard.horner" <ekkehard.horner(a)arcor.de> wrote in message
news:4bd8478b$0$6882$9b4e6d93(a)newsspool2.arcor-online.net...
> balzer schrieb:
>> two text files, doc1.txt and doc2.txt
>> document1.txt contains code which have names (absde.exe, etc) inside
>> double quotes.
>>
>> ReturnAPP_B ("absde.exe")
>> ReturnAPP_B ("dhdjd.exe")
>> ReturnAPP_B ("fhgfjfj.exe")
>>
>> Document2.txt contains list of files, each from new line
>> file1.exe
>> file2.exe
>> files3.exe
>> ...
>>
>> The task is just replace all files in doc1.txt inside pattern with files
>> from doc2.txt , i.e. replace "absde.exe" with "file1.exe", "dhdjd.exe"
>> with "file2.exe"and so on.
>> The quantity of files in doc1.txt and doc2.txt is n ot the same, doc1.txt
>> have more files, so the rest files in doc1.txt can be left as it, without
>> replacing.
>> How to make this with VBScript?
>>
>> Thanks.
>>
> I'm not sure that I understand your specs/problem (and your data/formats)
> correctly, but to get you started:
>
> Option Explicit
>
> Dim goFS : Set goFS = CreateObject( "Scripting.FileSystemObject" )
>
> WScript.Quit doMain00()
>
> Function doMain00()
> doMain00 = 1 ' assume error
> Dim reTo : Set reTo = New RegExp
> reTo.Global = True
> reTo.IgnoreCase = True
> reTo.MultiLine = True
> reTo.Pattern = "^\w+\.exe"
> Dim reFrom : Set reFrom = New RegExp
> reFrom.Global = True
> reFrom.IgnoreCase = True
> reFrom.Pattern = """\w+\.exe"""
> Dim sSource : sSource = goFS.OpenTextFile( ".\doc1.txt" ).ReadAll()
> WScript.Echo sSource
> Dim aRpl : aRpl = getRplTo( reTo, ".\doc2.txt" )
> addRplFrom aRpl, reFrom, sSource
> WScript.Echo "=====>"
> WScript.Echo applyRpl( aRpl, sSource )
> doMain00 = 0 ' reached this, so seems ok
> End Function
>
> Function getRplTo( reX, sFSpec )
> Dim oMTS : Set oMTS = reX.Execute( goFS.OpenTextFile(
> sFSpec ).ReadAll() )
> ReDim aRVal( oMTS.Count - 1, 1 )
> Dim nIdx
> For nIdx = 0 To UBound( aRVal )
> aRVal( nIdx, 1 ) = oMTS( nIdx ).Value
> Next
> getRplTo = aRVal
> End Function
>
> Sub addRplFrom( aRpl, reX, sSource )
> Dim oMTS : Set oMTS = reX.Execute( sSource )
> Dim nIdx
> For nIdx = 0 To UBound( aRpl )
> aRpl( nIdx, 0 ) = oMTS( nIdx ).Value
> Next
> End Sub
>
> Function applyRpl( aRpl, ByVal sSource )
> Dim nIdx
> For nIdx = 0 To UBound( aRpl )
> sSource = Replace( sSource, aRpl( nIdx, 0 ), qq( aRpl( nIdx, 1 ) ) )
> Next
> applyRpl = sSource
> End Function
>
> Function qq( sTxt )
> qq = """" & sTxt & """"
> End Function
>
> output:
>
> C:\wis\_vbs\0506\dev\forum\balzer
> cscript balzer.vbs
> contains code which have names (absde.exe, etc) inside double quotes.
>
> ReturnAPP_B ("absde.exe")
> ReturnAPP_B ("dhdjd.exe")
> ReturnAPP_B ("fhgfjfj.exe")
>
> The quantity of files in doc1.txt and doc2.txt is n ot the same,
> doc1.txt have more files, so the rest files in doc1.txt can be left as
> it, without replacing.
>
> ReturnAPP_B ("nottobechanged.exe")
> ReturnAPP_B ("keepmeto.exe")
>
> But what about a to-be-replaced exe - eg dhdjd.exe - occuring more
> than once
>
> ReturnAPP_B ("fhgfjfj.exe")
>
>
> =====>
> contains code which have names (absde.exe, etc) inside double quotes.
>
> ReturnAPP_B ("file1.exe")
> ReturnAPP_B ("file2.exe")
> ReturnAPP_B ("files3.exe")
>
> The quantity of files in doc1.txt and doc2.txt is n ot the same,
> doc1.txt have more files, so the rest files in doc1.txt can be left as
> it, without replacing.
>
> ReturnAPP_B ("nottobechanged.exe")
> ReturnAPP_B ("keepmeto.exe")
>
> But what about a to-be-replaced exe - eg dhdjd.exe - occuring more
> than once
>
> ReturnAPP_B ("files3.exe")
>
>
> I hope that based on this the discussion of specs (e.g. is it correct
> to map the nth occurrence of a To-exe to the nth occurrence of a
> From-exe) and implementation details (just ask for explanations)
> easier.
----------

does not work, just open this open Windows Script Hosy window with unchanged
content of doc1.txt, when close, open windows with "=====>", then again with
content of doc1.txt, then close. I just meant replace file names in doc1
with relevant files from doc2, doc1 has 254 records, doc1 - 250 recors, so
difference only 4 line, not a problem add this 4 manually.

From: ekkehard.horner on
balzer schrieb:
>
> "ekkehard.horner" <ekkehard.horner(a)arcor.de> wrote in message
> news:4bd8478b$0$6882$9b4e6d93(a)newsspool2.arcor-online.net...
>> balzer schrieb:
[...]
>>>
>> I'm not sure that I understand your specs/problem (and your data/formats)
>> correctly, but to get you started:
>>
[...]
code
>>
>> C:\wis\_vbs\0506\dev\forum\balzer
>> cscript balzer.vbs
>> contains code which have names (absde.exe, etc) inside double quotes.
>>
[...]
> ----------
> does not work, just open this open Windows Script Hosy window with
> unchanged content of doc1.txt, when close, open windows with "=====>",

that's why I asked you to use cscript

> then again with content of doc1.txt, then close. I just meant replace

are you sure this displays content of doc1.txt *unchanged*?

> file names in doc1 with relevant files from doc2, doc1 has 254 records,
> doc1 - 250 recors, so difference only 4 line, not a problem add this 4
> manually.

If I understand "record" to mean "line", the problem could be restated like

given a doc1.txt with n lines like

ReturnAPP_B ("a1.exe")
ReturnAPP_B ("a2.exe")
...
ReturnAPP_B ("an.exe")

and a doc2.txt with n lines like

file1.exe
file2.exe
...
filen.exe

generate a file doc3.txt like

ReturnAPP_B ("file1.exe")
ReturnAPP_B ("file2.exe")
...
ReturnAPP_B ("file1n.exe")

this could be done like this:

Option Explicit

Dim goFS : Set goFS = CreateObject( "Scripting.FileSystemObject" )

WScript.Quit doMain01()
WScript.Quit doMain00()

Function doMain01()
doMain01 = 1 ' assume error
Dim tsIn : Set tsIn = goFS.OpenTextFile( ".\doc2.txt" )
Dim tsOut : Set tsOut = goFS.CreateTextFile( ".\doc3.txt", True )
Do Until tsIn.AtEndOfStream
Dim sExe : sExe = tsIn.ReadLine()
Dim sCall : sCall = Replace( "ReturnAPP_B (""?"")", "?", sExe )
tsOut.WriteLine sCall
Loop
tsOut.Close
tsIn.Close
WScript.Echo goFS.OpenTextFile( ".\doc3.txt" ).ReadAll
doMain01 = 0 ' reached this, so seems ok
End Function

Function doMain00()
...
[rest of code unchanged]

output:

C:\wis\_vbs\0506\dev\forum\balzer
cscript balzer.vbs
ReturnAPP_B ("file1.exe")
ReturnAPP_B ("file2.exe")
ReturnAPP_B ("files3.exe")



From: balzer on

"ekkehard.horner" <ekkehard.horner(a)arcor.de> wrote in message
news:4bd86056$0$6878$9b4e6d93(a)newsspool2.arcor-online.net...
balzer schrieb:
>
> "ekkehard.horner" <ekkehard.horner(a)arcor.de> wrote in message
> news:4bd8478b$0$6882$9b4e6d93(a)newsspool2.arcor-online.net...
>> balzer schrieb:
[...]
>>>
>> I'm not sure that I understand your specs/problem (and your data/formats)
>> correctly, but to get you started:
>>
[...]
code
>>
>> C:\wis\_vbs\0506\dev\forum\balzer
>> cscript balzer.vbs
>> contains code which have names (absde.exe, etc) inside double quotes.
>>
[...]
> ----------
> does not work, just open this open Windows Script Hosy window with
> unchanged content of doc1.txt, when close, open windows with "=====>",

that's why I asked you to use cscript

> then again with content of doc1.txt, then close. I just meant replace

are you sure this displays content of doc1.txt *unchanged*?

> file names in doc1 with relevant files from doc2, doc1 has 254 records,
> doc1 - 250 recors, so difference only 4 line, not a problem add this 4
> manually.

If I understand "record" to mean "line", the problem could be restated like

given a doc1.txt with n lines like

ReturnAPP_B ("a1.exe")
ReturnAPP_B ("a2.exe")
....
ReturnAPP_B ("an.exe")

and a doc2.txt with n lines like

file1.exe
file2.exe
....
filen.exe

generate a file doc3.txt like

ReturnAPP_B ("file1.exe")
ReturnAPP_B ("file2.exe")
....
ReturnAPP_B ("file1n.exe")

this could be done like this:

Option Explicit

Dim goFS : Set goFS = CreateObject( "Scripting.FileSystemObject" )

WScript.Quit doMain01()
WScript.Quit doMain00()

Function doMain01()
doMain01 = 1 ' assume error
Dim tsIn : Set tsIn = goFS.OpenTextFile( ".\doc2.txt" )
Dim tsOut : Set tsOut = goFS.CreateTextFile( ".\doc3.txt", True )
Do Until tsIn.AtEndOfStream
Dim sExe : sExe = tsIn.ReadLine()
Dim sCall : sCall = Replace( "ReturnAPP_B (""?"")", "?", sExe )
tsOut.WriteLine sCall
Loop
tsOut.Close
tsIn.Close
WScript.Echo goFS.OpenTextFile( ".\doc3.txt" ).ReadAll
doMain01 = 0 ' reached this, so seems ok
End Function

Function doMain00()
....
[rest of code unchanged]

output:

C:\wis\_vbs\0506\dev\forum\balzer
cscript balzer.vbs
ReturnAPP_B ("file1.exe")
ReturnAPP_B ("file2.exe")
ReturnAPP_B ("files3.exe")
===================



No, does not work for me. I wasn't fully clear. The doc1.txt contain vaste
vbscript code, where these lines

ReturnAPP_B ("a1.exe")
ReturnAPP_B ("a2.exe")
....
are only the *part* of the full code, so this lines is inside a code, not
full content of doc1.txt.

Instead, the doc2.txt contains only n lines like

file1.exe
file2.exe
....
and so on.
No other strings or code in doc2.txt, only this list.