Page 1 of 1

base name variable in VBScript?

Posted: 10 Mar 2018 11:40
by yusef88
how to send base name of selected file to the following VBScript

Code: Select all

CreateObject("WScript.Shell").Run("""http://www.google.com/search?q="base name"" ")
may help:

Code: Select all

option explicit

Dim strFile, FSO, oFile

If WScript.Arguments.Count > 0 Then
  strFile = WScript.Arguments.Item(0)
End If

Set FSO = CreateObject("Scripting.FileSystemObject")

Wscript.Echo "FSO 'path' methods" & vbNewLine & "---------------------" _
   & vbNewLine & "GetBaseName: " & FSO.GetBaseName( strFile) _

Set FSO = Nothing
Wscript.Quit

Re: base name variable in VBScript?

Posted: 10 Mar 2018 11:54
by jupe
Just in case you weren't aware it can be done in XY directly like this:

Code: Select all

open "http://www.google.com/search?q=<curbase>";

Code: Select all

CreateObject("WScript.Shell").Run("http://www.google.com/search?q=" & CreateObject("Scripting.FileSystemObject").GetBaseName(WScript.Arguments.Item(0)))
OR

Code: Select all

CreateObject("WScript.Shell").Run("http://www.google.com/search?q=" & CreateObject("Scripting.FileSystemObject").GetBaseName(WScript.Arguments.Unnamed(0)))

Re: base name variable in VBScript?

Posted: 10 Mar 2018 13:05
by yusef88
thank you for your help
what about space in file name? (google will only search the first word before space)

Code: Select all

CreateObject("WScript.Shell").Run("http://www.google.com/search?q=" & CreateObject("Scripting.FileSystemObject").GetBaseName(WScript.Arguments.Item(0)))

Re: base name variable in VBScript?

Posted: 10 Mar 2018 13:38
by jupe
Try this:

Code: Select all

CreateObject("WScript.Shell").Run("http://www.google.com/search?q=" & CreateObject("Scripting.FileSystemObject").GetBaseName(replace(WScript.Arguments.Item(0), " ", "+")))
I should add that I have never really used VBScript so this may not be the correct way...

Re: base name variable in VBScript?

Posted: 10 Mar 2018 15:09
by yusef88
It works. thank you! :tup: