How can I wrap the current directory in lines in CMD?

I need to write a command that changes the current directory and prints a NEW directory wrapped in some tags. I thought I would cd SOMEPATH & echo wkd%cd%wkddo it, but there will be a problem.

Here is an example of input and output

C:\Users> cd .. & echo wkd%cd%wkd
wkdC:\Userswkd

As you can see, the OLD directory was printed. Why is this happening? I also tried using newlines (since I feed the command, although an external program), but this creates problems when starting the command line software.

I really hope there is a solution for this.

+4
source share
2 answers

(, ), /. , .

, , %cd% .

:

  • , .
    cd ..  
    echo wkd%cd%wkd
  • , %var% !var!, ,
    rem inside a batch file
    setlocal enabledelayedexpansion
    cd .. & echo wkd!cd!wkd

    rem from a command line
    cmd /v:on /q /c "cd .. & echo wkd!cd!wkd"
  • , echo, . call. , call , .
    rem inside a batch file
    cd .. & call echo wkd%%cd%%wkd

    rem from command line
    cd .. & call echo wkd^%cd^%wkd
  • , .
    rem from command line
    cd .. & for %A in (.) do echo wkd%~fAwkd
    cd .. & for /f %A in ('cd') do echo wkd%Awkd

    rem in batch files the percent sign needs to be escaped
    cd .. & for %%A in (.) do echo wkd%%~fAwkd
    cd .. & for /f %%A in ('cd') do echo wkd%%Awkd

(%~fA - , for %A)

, for /f for

  • for /f cmd, cd , do, , ,

  • for , ., . %~fA .

: , cd ...

+1

:

cd .. & For /F %A in ('cd') do echo wkd%Awkd

for loop , :

.

, , , % cd% ​​ , - , . foo bar .

0

All Articles