base name variable in VBScript?

What other productivity software are you working with...
Post Reply
yusef88
Posts: 945
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

base name variable in VBScript?

Post by yusef88 » 10 Mar 2018 11:40

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

jupe
Posts: 1177
Joined: 20 Oct 2017 21:14
Location: 1903 x64

Re: base name variable in VBScript?

Post by jupe » 10 Mar 2018 11:54

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)))

yusef88
Posts: 945
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: base name variable in VBScript?

Post by yusef88 » 10 Mar 2018 13:05

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)))

jupe
Posts: 1177
Joined: 20 Oct 2017 21:14
Location: 1903 x64

Re: base name variable in VBScript?

Post by jupe » 10 Mar 2018 13:38

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...

yusef88
Posts: 945
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: base name variable in VBScript?

Post by yusef88 » 10 Mar 2018 15:09

It works. thank you! :tup:

Post Reply