base name variable in VBScript?

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

base name variable in VBScript?

Post 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

jupe
Posts: 2757
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: base name variable in VBScript?

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

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

Re: base name variable in VBScript?

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

jupe
Posts: 2757
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: base name variable in VBScript?

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

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

Re: base name variable in VBScript?

Post by yusef88 »

It works. thank you! :tup:

Post Reply