Relative Path in Vbscript

Asked

Viewed 168 times

1

I want to associate a XML is an application in VBScript and I need to indicate in the application which directory should read the XML, however, as is easy to predict, Path of XML can’t be hardcoded.

Is there any way to VBScript indicate "../PastaAplicacao/Ficheiros/config.xml" with VBScript?

1 answer

1


You can both take the file path and treat:

Dim caminhoArquivo, segmentosCaminhoArquivo, nomeArquivo, caminhoPastaAtual

caminhoArquivo = Wscript.ScriptFullName
segmentosCaminhoArquivo = Split(caminhoArquivo, "\")

nomeArquivo = segmentosCaminhoArquivo(UBound(segmentosCaminhoArquivo))
caminhoPastaAtual = Left(caminhoArquivo, Len(caminhoArquivo) - Len(nomeArquivo))

Or even take the current directory when instantiating an object:

Set objShell = CreateObject(“Wscript.Shell”)

caminhoPastaAtual = objShell.CurrentDirectory

From there, you can use the relative path with:

caminhoOutraPasta = caminhoPastaAtual & "..\pastaIrma\"
caminhoOutraPasta2 = caminhoPastaAtual & "pastaFilha"

I hope I helped the/

Browser other questions tagged

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