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
  • 297,002
  • 52
  • 306
  • 350
Nicholas Adamou
  • 711
  • 10
  • 23

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,749
  • 11
  • 23