Txt file directory with VBS

Asked

Viewed 1,026 times

3

My VBS code is 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 inside my folder (from the script) and find it, without needing a literal path?

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

That way I still can’t.

1 answer

2

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)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.