DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

problem with relative path syntax in.vbs

Hello,

I want to access a file in an upper path hirarchy in order to include a script
via command: call ScriptInclude("..\Test\Main.vbs").
But the "..\" doesn't work and so an error message appears.

How can I reach going up in the path?

Kind regards,
Jan
0 Kudos
Message 1 of 7
(11,191 Views)
Hi Jan,

there is a variable you might want to use:  AutoActPath specifies the path of the script file currently running.
Is that what you are looking for?

regards
Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 2 of 7
(11,182 Views)

Hi,

Ingo wrote: ...Is that what you are looking for?

Sorry, but it isn't.

I suppose knowing my path, because when I copy the include-script

in the folder with the file, which includes it like that:  ScriptInclude("\Main.vbs"), it will work.

Only the "..\" syntax might be the problem ?

Kind regards,

Jan  

0 Kudos
Message 3 of 7
(11,179 Views)
I guess I did not understand you correctly in the beginning.

Let me first check if I got it now:
Your script located at a path like c:\project\path1\script.vbs
and you would like to include a file that is furher up in the hierarchy, say c:\project\include.vbs.
And you would like to use a relative path for it.
Is that correct?

Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 4 of 7
(11,172 Views)
Hi Jan,
Seems like the issue is due to a limitation of VBS.
To access a parent directory you cannot just use a syntax like "..\".
To get access to functionality like that I think you have to use the FileSystemObject which I admit is a bit more complicated to use but it comes with some useful properties.

Try something like that:
Option Explicit  'Forces the explicit declaration of all the variables in a script.
DIM FSO, folder, txt
txt = "path of calling script : " & autoactpath &vbcrlf

Set FSO = CreateObject("Scripting.FileSystemObject")
Set folder = FSO.GetFolder(autoactpath)

txt = txt & "parent path : "&folder.parentfolder&vbcrlf
txt = txt & "drive : "&folder.drive

msgbox txt
scriptstart folder.parentfolder&"\run.vbs"

Maybe it helps to answer qour question.
Of course you could reduce the example to a two line script in your application:
DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
This Line needs only to be called once. It creates an instance  of the  FilesystemObject, whic is parent to the  folder object
scriptstart FSO.GetFolder(autoactpath).parentfolder&"\run.vbs"
This line should run with the Scriptinclude command as well. I just tested with scriptstart

Let me know if it works.
Regards

Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 5 of 7
(11,165 Views)

Hi Jan,

if you don't like fso...:

  option explicit
  dim intFolderNameLen, strText, intChar

  ' if you know the length of your foldername
  intFolderNameLen  = 4 ' hardcoded the length of your "deepest" Foldername add 1 for the "\"
  intChar           = len(AutoActPath) - intFolderNameLen
  strText           = cop(AutoActPath, intChar)
  msgbox strText

  ' if the length isn't fix
  intChar           = InStrRev(AutoActPath,"\",len(AutoActPath)-1,1) ' looking for the 2nd last "\" -> len-1
  strText           = cop(AutoActPath, intChar)
  msgbox strText

 

greets Andreas

Volkswagen AG
Wolfsburg - Germany
0 Kudos
Message 6 of 7
(11,150 Views)

Hello Ingo, hello Andreas.

Thank you both for helping me. I decided to implement the fso..-solution,

but the other solution looks good as well.

Kind regards,

Jan

 

0 Kudos
Message 7 of 7
(11,147 Views)