Click to See Complete Forum and Search --> : How to extract path of itself from a .bat under DOS


love2mao
May 24th, 2004, 11:14 AM
Hi gurus,
I have this question: I scheduled a task to call a .bat file.
I want to get the path of this .bat in the file itself. Of course,
the location of this .bat file changes.

I've thought I can use "CD" to get it, and I can so this if I run
the .bat from its location, however, when the task scheduler calls
it, "CD" returns "c:\WINNT\system32". Just no idea how to go
ahead

:sick:

TheCPUWizard
May 24th, 2004, 11:24 AM
Why use a bat file?

Using Windows Scripting... Much more powerful...

Bond
May 25th, 2004, 02:46 PM
If you're using the full path to the BAT file in your scheduled task, then try using %0 to return this information.

For example, if you use the following code in your BAT file:

@echo %0

Then, this will ECHO the path to the BAT file. Just be sure to supply the full path (not a relative one) when adding it to your scheduler.