Re: how to get the bat file self's path in a bat file?



hantechs@xxxxxxxxx wrote:

Is there a way to get the bat file self 's path in a bat file?Thx

Hi,

To get the path not including the bat file name, you need to parse %0:

@echo off
set scriptpath=%~d0%~p0
echo %scriptpath%


For more on the %~ parameters, at the command prompt enter "FOR /?"



--
torgeir, Microsoft MVP Scripting, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
.



Relevant Pages

  • Re: Error after scanning without any error number .
    ... AutomaticUpdates with code Call complete and error 0 ... help with this problem Torgeir. ... > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.windowsupdate)
  • Re: Attn: Torgeir Bakken - Import OE IAF LDAP file via Kixtart logon script
    ... Thanx Torgeir: ... I'll look ant the REG file export/import method. ... | torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.windows.server.scripting)
  • Re: Cant apply security patches
    ... server has been patched, can I remove what is in there? ... "Torgeir Bakken " wrote: ... > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.win2000.general)
  • Re: How to communicate with a batch file
    ... Thanks Torgeir, that exactly what I'm looking for! ... > echo %regvaluedata% ... > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.scripting.vbscript)
  • Re: 0x8007041D Has Anyone found a reliable fix?
    ... Cheers Torgeir, all solved for me at least :-) The reverse tracking idea ... through the event log system area put me on the path. ... > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.windowsupdate)