Saturday, December 3, 2011

Tip about @ScriptDir

You may someday find yourself in the situation I was in not too long ago.  It's a script where I was working with several directories and having to use FileChangeDir() quite a bit.  Of course that changes the working directory from it's normal location which is @ScriptDir.  That also meant that in order to use a couple of exe files that were stored in the scripts folder I would either have to use a FileCopy or FileMove to put those files in a folder that is in the path environment; for example the Windows folder.  If I didn't do that it meant that everytime I wanted to call one of those files I had to specify it with @ScriptDir & "\somefile.exe".  Since those files had to be called quite often I chose another route.
Near the top of your script just add the following line.
EnvSet("path", EnvGet("path") & ";" & @ScriptDir)  That adds the script directory to the path environment but only so long as the script is running.  It's not a permanent change unless you use EnvSave("path").  That means I can then call the file without a path and without worrying about what my current working dir is.
Example:
ShellExecute("myfile.exe") would be the same as using ShellExecute(@ScriptDir & "\myfile.exe") but with a lot less typing involved.

3 comments:

p19z said...

Clever idea, I should try that. Thanks.

Vincent said...

I'll give that a shot also, seems to be similar to another automation program where the code is {curdir}

Admin said...

It's okay to mention the other program around here. It's not like the foirums where you could get flamed for doing that.