Locate Script Path

11 posts / 0 new
Last post
tme
Offline
Joined: 05/08/2017 - 02:36
Locate Script Path

Hi Brian,is it possible to find out at which path the script is running, so I can save the value in a variable.Thanks
 

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi tme and welcome to the site.

Are you talking about the project folder, there is a command that will return the path of your project which would generally be where the script is running.  You can find it with the following command:

Current = Client.WorkingDirectory()

Let me know if I understood what you are looking for.

Thanks

Brian

tme
Offline
Joined: 05/08/2017 - 02:36

Thank you for the quick response, but this is not what I'm talking about. I want to save the directory of my IDEA-script in a variable not the working directory of my IDEA-project. I have a folder structer with several scripts. There is also one start script, where you can navigate to other scripts dependent of your choise. If I distribute this folder structure with the scripts to a user, it should be possible to run the script and navigate through all scripts. I don't want to pretend a fixed directory where all scripts have to be. That's why I want to save the directory of the script in a variable to handel the navigation dynamicly.

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi tme,

I don't know of a way to do this.  My only suggestion is create your folder structure under the project folder so that someone can put it in any project, you would then have the folder structure and just add the project path to it.  

Brian

tme
Offline
Joined: 05/08/2017 - 02:36

Hi brian,
this is no solution for me, but thank you very much for the fast response. If I have a solution, I will communicate it here.
tme

wisonix
Offline
Joined: 09/26/2017 - 11:11

Hi, I am from Berlin (Germany).
Because I have the same problem, I've tried some VB-script-tips from the web:
 
Solution 1: with WScript..

Set fso = CreateObject("Scripting.FileSystemObject")

WScript.Echo fso.GetParentFolderName(WScript.ScriptFullName)

 
Solution 2: with WScript...
 

With WScript

MyPath = Replace(.ScriptFullName&":", .ScriptName&":", "")

.Echo MyPath

End With

 
Solution 3: without WScript...
 
 Set fso = CreateObject("Scripting.FileSystemObject")
 sPath = fso.GetFolder(".") & "\"
 
 
My problem(s): Solution 1 + 2 doesn't work, because WScript is deactivated on our Laptops...
and Solution 3 doesn't work sure (the result is not ever correct).
 
wisonix

 
 

 

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hello wisonix and welcome to the site.

Where are you storing your macros?  Is it under the project folder?

Brian

AndreBorges
Offline
Joined: 07/26/2017 - 06:03

I have the same question. 
For example I have my .iss file saved on desktop, and my goal is to obtain the path of this file, something like "C:\Users\xxx\Desktop\".
at this time I only can get the name of the current IDEA project when I run both codes that I share below:
MsgBox Client.WorkingDirectory()
Set WScript = CreateObject("WScript.Shell")
 
MsgBox WScript.CurrentDirectory
any of you have solved this issue?

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Would something like this work for you?


Sub Main
	Dim objShell As Object
   	Dim strPath As String

   	Set objShell = CreateObject("Wscript.Shell")
   		strPath = objShell.SpecialFolders("Desktop")
   		MsgBox strPath
   	Set objShell = Nothing
End Sub
AndreBorges
Offline
Joined: 07/26/2017 - 06:03

thank you for the prompt reply Brian.
If fact what I want is to get the  .iss File path. (Your code only will work if I have my file saved on desktop)
 
what I expected is something similiar to what we have in VBA:
Application.ActiveWorkbook.Path
 
thanks,
André

klmi
Offline
Joined: 02/13/2019 - 08:41

I suggest to use a special *. ini file were the path is set manually. Your macros could read that file and use the given path.
edit: I use the path of the Local Library to save that *.ini file. You will get that path with Client.LocalLibraryPath(). When the script runs for the first time and doesn't find that *.ini file a dialog to set the paths is shown.