Question : Dragging a file onto a batch changes working directory

If I double-click my bat script, it executes in .
But if I drag a file onto it, it executes in %HOMEPATH%.
Why is this? How to prevent it? If not preventable, how to access files in . from the bat script when this happens?

E.g. when I double-click a .bat file with the code below, cd prints the containing folder's path - say C:\temp .
But when I drag a data file onto the .bat file, cd prints
C:\Documents and Settings\User

As you can see, all I need the bat file to do is execute an awk script on the data file.
Using Windows XP x86 SP3

Thanks for any help.
Code Snippet:
1:
2:
3:
4:
5:
@echo off
 
cd
REM gawk.exe -f split.awk %1
pause
Open in New Window Select All

Answer : Dragging a file onto a batch changes working directory

Strange.

Fix it like this.
1:
2:
3:
4:
5:
6:
7:
@echo off
 
cd
cd /d %~dp0
cd
REM gawk.exe -f split.awk %1
pause
Open in New Window Select All
Random Solutions  
 
programming4us programming4us