WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: ltwert on March 30, 2015, 03:19:09 PM

Title: Get path to .wbt script file?
Post by: ltwert on March 30, 2015, 03:19:09 PM
I have searched the forums and tech support areas, but have not found anything about what I would believe is an obvious question:

Is there a way to get the path to the currently executing .wbt file? 

Or if it is compiled, to get the path to the .exe file?

Thanks...
Title: Re: Get path to .wbt script file?
Post by: JTaylor on March 30, 2015, 03:21:43 PM
DirScript()?

Jim
Title: Re: Get path to .wbt script file?
Post by: td on March 31, 2015, 06:35:45 AM
DirScript is, of course, documented in the WIL Consolidated Help file.
Title: Re: Get path to .wbt script file?
Post by: snowsnowsnow on April 02, 2015, 03:33:21 PM
DirScript() returns a directory, which is not exactly the same thing as the path to the .WBT.

Surely, we are overlooking IC(1004) here, are we not?
Title: Re: Get path to .wbt script file?
Post by: kdmoyers on April 03, 2015, 04:56:56 AM
Agreed,
IntControl(1004,0,0,0,0) is what I use
Title: Re: Get path to .wbt script file?
Post by: td on April 03, 2015, 06:43:09 AM
Quote from: snowsnowsnow on April 02, 2015, 03:33:21 PM
DirScript() returns a directory, which is not exactly the same thing as the path to the .WBT.

Surely, we are overlooking IC(1004) here, are we not?

In computing the term 'path' can be used to indicate either the directory (folder in MSFT speak) location of a file (absolute or relative) or a full file system location which includes a file root name and any extension. DirScript returns the former and IntControl 1004 returns the latter.

Basically, DirScript  removes the necessity of calling FilePath  on the returned result from IntControl 1004 .

The OP's post could easily be interpreted as indicating the need for either return result.  Since the OP never responded to the Jim's original reply, perhaps DirScript provided the desired result. Or perhaps the OP notices the reference to IntControl 1004 in the documentation for  DirScript and used that instead.   
Title: Re: Get path to .wbt script file?
Post by: snowsnowsnow on April 03, 2015, 10:30:32 AM
Yes, you are right.  Either interpretation is possible.

I just assume, based on my own experience, that wanting the full filename, not the directory, is the more common request.

Personally, I think if it was the directory that was being sought, the request would have been worded differently.

But that's just me...
Title: Re: Get path to .wbt script file?
Post by: stanl on April 04, 2015, 03:55:03 AM
Quote from: snowsnowsnow on April 03, 2015, 10:30:32 AM
Personally, I think if it was the directory that was being sought, the request would have been worded differently.

lol.  Reminds one of Stackoverflow.
Title: Re: Get path to .wbt script file?
Post by: snowsnowsnow on April 06, 2015, 08:22:50 AM
I don't know what that means.

(But then again, I've never used "Stack Overflow")
Title: Re: Get path to .wbt script file?
Post by: ltwert on April 13, 2015, 09:21:56 AM
DirScript is what I was looking for, and IntControl(1004 is also interesting for the future.

Thanks everyone!
Title: Re: Get path to .wbt script file?
Post by: DAG_P6 on April 30, 2015, 08:15:03 PM
Quote from: ltwert on April 13, 2015, 09:21:56 AM
DirScript is what I was looking for, and IntControl(1004 is also interesting for the future.

Since it returns the whole path, I prefer IntControl(1004, because once call gets a string from which the path and the program name are easily extracted.
Title: Re: Get path to .wbt script file?
Post by: td on May 01, 2015, 07:02:34 AM
When you need the script's full path with file name and extension call IntControl 1004.  When you need the script's path call DirScript. There is no reason to prefer one over the other because there is no advantage to parsing the path component from the IntControl 1004 return value yourself instead of calling DirScript.

The only time where it might be better to use IntControl 1004 for the path is a case where you need to pass both script name and path information to another script or executable. Even in that case, the advantage of using IntControl 1004's would depend on how you passed the info.
Title: Re: Get path to .wbt script file?
Post by: DAG_P6 on May 01, 2015, 02:33:36 PM
I usually save both in my startup code, so that I have the program name for use in the message box caption, and the path for finding satellite files.
Title: Re: Get path to .wbt script file?
Post by: td on May 01, 2015, 02:57:09 PM
Then you can use both DirScript and IntControl 1004.  With Dirscript you can use the path without having to worry about variable scope or alternatively having to reparse.
Title: Re: Get path to .wbt script file?
Post by: DAG_P6 on May 02, 2015, 08:46:38 AM
That's why I've started establishing pointers to them. Nevertheless, for small routines that I want to keep lean and mean, I use dirscript.
Title: Re: Get path to .wbt script file?
Post by: td on May 02, 2015, 09:02:34 AM
WinBatch pointers are expensive and add complexity to a script. There are reasons for using them but, IMHO, when you have a function like DirScript, this isn't one of them.
Title: Re: Get path to .wbt script file?
Post by: DAG_P6 on May 07, 2015, 04:21:05 PM
Quote from: td on May 02, 2015, 09:02:34 AM
WinBatch pointers are expensive and add complexity to a script. There are reasons for using them but, IMHO, when you have a function like DirScript, this isn't one of them.

Since I suspected as much, I've gone back and forth mentally about that. Thanks for confirming my guess.