PC Review


Reply
Thread Tools Rate Thread

Can a batch file capture its own location?

 
 
David Mayerovitch
Guest
Posts: n/a
 
      18th Nov 2006
I want a batch file to be able to reference its own location in the folder
tree.

I create the file C:\FOOBAR\MYSELF.BAT:

@echo off
echo This batch file is in folder %CD%
pause


This returns, as expected, the following output:

This batch file is in folder C:\FOOBAR


However, if I launch the file by dropping another file onto it, I get this:

This batch file is in folder C:\Documents and Settings\David

which is my home directory.


How can I capture the actual physical location of the batch file even when
it is launched by having a file dropped on it?

Special bonus question: Why does the command-line interpreter behave in this
way?

Thanks.

David


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch File Rename + Date added & Move to another location carla_cund@hotmail.com Microsoft Windows 2000 CMD Promt 19 19th Jan 2007 08:51 AM
Batch file that will capture screen and ftp asarangan@yahoo.com Windows XP Basics 2 19th Mar 2006 01:01 PM
Batch file to Capture VPN IP address =?Utf-8?B?RGF2aWQ=?= Windows XP General 2 6th Oct 2005 04:38 PM
Use reg.exe to capture value in a variable for batch use? Craig Microsoft Windows 2000 Registry 2 29th Sep 2003 01:42 PM
Use reg.exe to capture value in a variable for batch use? Craig Microsoft Windows 2000 Registry Archive 4 29th Sep 2003 01:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:01 PM.