3

I have been using QTTabBar for a while and am using .js scripts with it. The scripts are run using Windows Script Host, but I find myself having to specify hardcoded directories in the .js file instead of relative paths. This is not ideal.

In the .js file, is it possible to get the containing folder of the .js file (no matter what directory it is originally run from)? I just need to avoid specifying absolute paths somehow. For example, part of my .js file might look like this:

var qs = new ActiveXObject( "QTTabBarLib.Scripting" );

var fso = new ActiveXObject("Scripting.FileSystemObject");
var txtFile = fso.OpenTextFile("C:\\Installation\\Scripts\\QTTabBar\\dirs.txt", 1, false, 0);
var fText = txtFile.ReadAll();

I can't just put "dirs.txt" in the OpenTextFile function because when the .js script is run in QTTabBar, the working directory (I think) starts in system32 rather than at the .js file location. So I somehow need to get the path of the .js file itself and combine it with the relative name to create the absolute path. But I'm not sure if this is possible or how to do it.

1 Answer 1

2

You can get the path of current JScript file with

js_file_path = WScript.ScriptFullName;

and the absolute path to the text file is

path = WScript.ScriptFullName.split("\\").slice(0, -1).join("\\") + "\\dirs.txt";

No includes or imports are needed if the script is run in Windows Script Host.

Sign up to request clarification or add additional context in comments.

1 Comment

I love getting answers 2 years later. I actually had never found a solution and left them hardcoded this whole time. This worked great and now my scripts are updated. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.