Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I determine the current directory in a batch file. Other than %~dp0.

So that when I run the batch file from source folder (consisting of my files) it returns the path of source folder, where ever it may be.

share|improve this question
add comment

1 Answer

The environment variable %cd% contains the current folder:

H:\Downloads>type currentdir.bat
echo %cd%
H:\Downloads>currentdir.bat

H:\Downloads>echo H:\Downloads
H:\Downloads

H:\Downloads>
share|improve this answer
    
Bear in mind that batch processing may require double-%, so %%cd%%. –  user3463 Aug 8 '12 at 6:18
2  
@RandolphWest, not for this case –  Sean Cheshire Aug 8 '12 at 18:29
    
That's good to know. –  user3463 Aug 8 '12 at 20:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.