0

I am trying to get the file path of the batch script file that I made. I want the script to take the current path of the batch file and remove the file name and stores it in a variable, so it looks like this:

C:/path/to/batch/

Not like this: C:/path/to/batch/file.bat

I don't want: file.bat in the file path.

Here is my batch file:

@echo off
echo grabbing file path...
set filePath=%0
pause %filePath%
3
  • 1
    Lookup the %~dp modifers in call /?. Commented Dec 31, 2015 at 22:49
  • @dxiv alrighty, thanks for your input. Commented Dec 31, 2015 at 23:03
  • I google searched your exact question and the first 4 links were links to StackOverFlow giving the same answer about using the modifiers dp. Commented Jan 1, 2016 at 1:45

1 Answer 1

1

As given in the answer to this question: Get current batchfile directory you can accomplish what your after with

%~dp0

so in your example code

@echo off
echo grabbing file path...
set "filePath=%~dp0"
echo %filePath%
pause

Edit - fixed space and added quotes as suggested by commenter

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.