Praveen
Praveen

Reputation: 902

Batch script issue with the current directory

I have used a batch file in which i am setting absolute path variable as below

Code snippet(Batch File : brk_validation.bat)

SET ABS_PATH=%~dp0

echo  Completed the Validation of files in %ABS_PATH%

Running the Batch Program on command prompt:

D:\Files>brk_validation.bat .

Output :

Completed the Validation of files in D:\Files\

Issue:

I have put the batch file in a different directory and then running the bat file by giving the full path of it as shown below:

 D:\Files>D:\Work\brk_validation.bat .

Output :

Completed the Validation of files in D:\Work\

Expected Output:

Completed the Validation of files in D:\Files\

I want the current directory path where the files are present i.e. D:\Files for the above example.

So any help is appreciated. Thanks !!

Upvotes: 0

Views: 77

Answers (2)

Alex K.
Alex K.

Reputation: 175766

For the current directory;

SET ABS_PATH=%cd%

Upvotes: 2

martin
martin

Reputation: 2638

It should be SET ABS_PATH=%~dp1 The %0 variable is the filename of the batch file itself.

Upvotes: 0

Related Questions