Jamie
Jamie

Reputation: 1094

%~dp0\ shows error message

This is a simple question.

A while ago, when I was writing program, I wrote this:

set /p a=<%~dp0\a.txt

And this worked.

Recently, when I am writing program, I wrote this:

set /p a=<%~dp0\a.txt

And this didn't worked.
So I have to use THIS:

set /p a=<%~dp0a.txt

But it's mysterious. How can I use %~dp0 without \?
So mysterious. Anybody could explain?
ANY help will be appreciated. Even Commenting.

Upvotes: 2

Views: 1000

Answers (2)

Tool Box
Tool Box

Reputation: 71

Because %~dp0 is with \, you can use it without another \.

Upvotes: 1

foxidrive
foxidrive

Reputation: 41244

Place this in a folder and run it, and look at the end of the path echoed on the screen.

@echo off
echo "%~dp0"
pause

You will see that it has a terminating backslash so a filename can be run against it.

In many cases in modern Windows two \\ in a row in a path will also work, but not all the time.

Upvotes: 2

Related Questions