tags:

views:

75

answers:

2

In my bat script, I'm calling another script and passing it a string parameter

cscript log.vbs "triggered from folder <foldername> by Eric"

The string parameter as you can see contains the name of the folder from which the script is being called. What's the right way to pass this dynamically insert this folder name to the script?

A: 

Try %~dp0.

Here: http://weblogs.asp.net/whaggard/archive/2005/01/28/get-directory-path-of-an-executing-batch-file.aspx

Isaac
This gives the folder where the bat script is stored, which may or may not be the same as from where the script is being called, so it doesn't work in my case, because almost always it's being called from a different location that's different from where the script is actually stored.
Berming
+3  A: 
paxdiablo
@Berming, I've added code which will give you the last component of the path. See the update.
paxdiablo
Just what I needed, thank you very much. I noticed though that when I `endlocal` I can't access the `folder` variable after that, so I took out that line. I figured since I removed that line, I should also remove the `@setlocal enableextensions enabledelayedexpansion` at the top, but removing that line caused problems, so I kept that one.
Berming
paxdiablo