Page 1 of 2
Help with Batch / VBScript
Posted: 26 Dec 2010 19:13
by rfpd
Hey guys some time ago i created one file in visual basic script (a file that replaces text) that you just need to move the file to the program icon, and it replaces the text for what we want. But i want to know if it's possible to do what i said but in Batch.
Re: Help with Batch / VBScript
Posted: 26 Dec 2010 19:39
by aGerman
You should enhance your verbosity level. Nobody knows your VBScript and nobody knows what part of what string you want to replace with which substring. Give an example.
BTW: Did you read
http://www.dostips.com/forum/viewtopic.php?f=3&t=1516?
Regards
aGerman
Re: Help with Batch / VBScript
Posted: 26 Dec 2010 19:44
by ghostmachine4
rfpd wrote:Hey guys some time ago i created one file in visual basic script (a file that replaces text) that you just need to move the file to the program icon, and it replaces the text for what we want. But i want to know if it's possible to do what i said but in Batch.
if you already have a vbscript for that, then why use batch? batch (cmd.exe commands) is not suitable for file processing/manipulation, period.
Re: Help with Batch / VBScript
Posted: 27 Dec 2010 05:42
by rfpd
no guys loll u didn't understand, i got the code a code in the internet but i al ready deleted. But for a vbs work you need to move 1 file to the vbs and then code runs i wanted to do that but in batch.
Re: Help with Batch / VBScript
Posted: 27 Dec 2010 06:05
by aGerman
rfpd wrote:But for a vbs work you need to move 1 file to the vbs and then code runs i wanted to do that but in batch.
If I didn't get you wrong then "move" means "drag and drop" in this case?
Drop a file onto this batch:
As you can see the file comes as argument %1.
Regards
aGerman
Re: Help with Batch / VBScript
Posted: 27 Dec 2010 10:30
by rfpd
sorry i explain very bad but what i was asking was a batch code that drags and drops other files into a vbs.
Re: Help with Batch / VBScript
Posted: 27 Dec 2010 11:13
by aGerman
rfpd wrote:sorry i explain very bad but what i was asking was a batch code that drags and drops other files into a vbs.
Yeah sometimes it's not easy to understand what you're looking for.
OK. You can call a VBS with arguments as well.
The first argument you will find in
WScript.Arguments(0), the second in
WScript.Arguments(1) etc.
For testing we have 3 Files in the same directory:
test.txt
test.vbs
Code: Select all
WScript.Echo Replace(WScript.CreateObject("Scripting.FileSystemObject").OpenTextFile(WScript.Arguments(0), 1).ReadAll, WScript.Arguments(1), WScript.Arguments(2))
test.bat
Code: Select all
@echo off &setlocal
cscript //nologo "test.vbs" "test.txt" "d" "t"
pause
As you can see "test.txt" is the first argument for the VBS, "d" the second and "t" the third.
Now you can double click test.bat to find out what happens.
Regards
aGerman
Re: Help with Batch / VBScript
Posted: 27 Dec 2010 13:02
by rfpd
aGerman thanks but what i really whant is that the vbs replaces on the file no on the cmd only. Because what i want to do it's a batch that replaces strings in another batchs and multiple search
Re: Help with Batch / VBScript
Posted: 27 Dec 2010 15:27
by ChickenSoup
I'd try to help but, I'm not understanding exactly what you want to do.
Re: Help with Batch / VBScript
Posted: 27 Dec 2010 15:36
by aGerman
@ChickenSoup
This is my problem as well.
@rfpd
http://www.dostips.com/forum/viewtopic.php?f=3&t=1075&start=0Why don't you use it? What is wrong with this Xchange.vbs and what didn't you understand?
AND AGAIN: If you cannot explain what you need then use an example to show the problem!
Regards
aGerman
Re: Help with Batch / VBScript
Posted: 27 Dec 2010 17:35
by rfpd
vbscript:
Code: Select all
'fix.vbs
findWhat = Array("…", "Ά", "Έ")
replaceWith = Array("...", "'A", "'E")
For Each arg In WScript.Arguments
Set Doc = GetObject(arg)
Doc.Application.Visible = True
For i = 0 To UBound(findWhat)
Doc.Range(0, Doc.Application.Selection.End).Find.Execute _
findWhat(i), True, False, False, False, False, True, 1, _
False, replaceWith(i), 2, False, False, False, False
Next 'i
Next 'arg
Video explaining:
http://www.youtube.com/watch?v=w8riNo2XQsUAnd i also want to the file do the replace in batch files not in doc.
Re: Help with Batch / VBScript
Posted: 27 Dec 2010 19:21
by aGerman
Now I think I know what you try to do: You want to replace code of a batch file using VBScript.
VBS:
Code: Select all
findWhat = Array("…", "Ά", "Έ")
replaceWith = Array("...", "'A", "'E")
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
text = oFSO.OpenTextFile(WScript.Arguments(0), 1).ReadAll
If Not text = "" Then
For i = 0 To UBound(findWhat)
text = Replace(text, findWhat(i), replaceWith(i))
Next
End If
oFSO.CreateTextFile(WScript.Arguments(0)).Write text
Drag and drop your batch file onto this VBScript.
Regards
aGerman
Re: Help with Batch / VBScript
Posted: 28 Dec 2010 06:03
by rfpd
Thanks aGerman. But imagin we have files:
-the one to be replace.bat
-replacer.vbs
-other.bat
It's possible to the file "other.bat" drag "the one to be replace.bat" and drop into "replacer.vbs"?
Ps: The vbs replaces hey for bye but if i put HeY that doesn't replace.
Re: Help with Batch / VBScript
Posted: 28 Dec 2010 07:24
by aGerman
rfpd wrote:It's possible to the file "other.bat" drag "the one to be replace.bat" and drop into "replacer.vbs"?
It's exactly what I told you some posts before. You can call the vbs with a filename as argument. You will find a
dropped file or the
first argument of a command line in "WScript.Arguments(0)" as well.
other.bat
Code: Select all
@echo off &setlocal
cscript //nologo "replacer.vbs" "the one to be replace.bat"
rfpd wrote:Ps: The vbs replaces hey for bye but if i put HeY that doesn't replace.
Yes, the replace function of VBScript is case sensitive by default. Two possible solutions:
1st - You have to write another element to both arrays for HeY.
2nd - You change the code of the vbs as follows:
text = Replace(text, findWhat(i), replaceWith(i), 1, -1, vbTextCompare)Regards
aGerman
Re: Help with Batch / VBScript
Posted: 28 Dec 2010 08:28
by rfpd
thx a lot aGerman. But can i put it for replace multiple files?
Code: Select all
@echo off &setlocal
cscript //nologo "replacer.vbs" "*.txt"
pause
But that doesn't work. Thanks in advance.