File directory txt with VBS

2

My code in VBS looks like this:

Dim oShell
Set oShell = Wscript.CreateObject("WScript.Shell")
filename = "C:\Users\Public\Documents\Copy_File.txt"
oShell.Run(filename)

Is there any way I can leave this txt file that I need to access within my (script) folder and fetch it without needing a literal path?

Ex: Script inside Copy folder, txt file inside Copy folder and path passed in filename something like: ..\Copy ?

This way I still can not.

    
asked by anonymous 11.08.2015 / 22:49

1 answer

1

You can capture the current directory through the object Scripting.FileSystemObject :

Dim oShell, oFso

Set oShell = Wscript.CreateObject("WScript.Shell")
Set oFso = CreateObject("Scripting.FileSystemObject")

DiretorioAtual = oFso.GetAbsolutePathName(".")
Arquivo = DiretorioAtual & "\Copy_File.txt"

oShell.Run(Arquivo)
    
12.08.2015 / 00:55