What I want:
This should change directory to the path. Of course, on other drives this does not work in one line without
cd /D !pathname!.
My test/debug code looks as follows:
cls set @InDrive=%~d0 echo /D K:\ echo /D !@InDrive!\ echo !@InDrive!\ cd /D K:\ cd /D !@InDrive!\ !@InDrive!\ cd /D K:\
@ sign is required for the line
Without it, the variable would not even be set.
Result of my code is as follows:
/D K:\ /D K:\ K:\ Der Befehl "K:\" ist entweder falsch geschrieben oder konnte nicht gefunden werden.
The syntax error comes from the line
But when I echo the line, and copy the output of the line as is, it changes the directory. It is strange, that entering the exact output by hand works, but inside the batch script it does not work. What is going on? Btw: I ran the script and the command, that lies in the variable
!@InDrive! in the same cmd.exe window. So nothing changed in the background. (Remember:
cd /D K:\ should work as it does, when writing it manually)
What is wrong with it? Is this one of the hundrets of errors from the windows 10 updates recently?
I could swear, that I used a command like this years ago with succes. But I do not have the scripts anymore.
The search did not yield any result unfortunately. Anyone knows the source of the error? Goal is a script that works with relative paths, so I need to get a working CD. (I will use
set @InPath=%~dp0input\, which does echo out as expected when using
I also tried
pushd and it works, written by hand, but not in batch script. So this is not the answer unfortunately.
When I disable
SETLOCAL EnableDelayedExpansion it works! But I am absolutely required to use
What could be a clean workaround? When I CD before
SETLOCAL EnableDelayedExpansion it works, but I want to cd inside the loop.
cd %pathname%.. better still, try
cd /d %pathname%.. the /d allows it to switch between drives too.
%it works well, except for the line "%@InDrive%\" that should be just
%problem. I tried it with no variables at all (just batch file with cd). It also does not work.