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%
Mureinik
  • 277,661
  • 50
  • 283
  • 320
Nicholas Adamou
  • 631
  • 7
  • 19

1 Answers1

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

Community
  • 1
  • 1
norlesh
  • 1,669
  • 10
  • 22