This doesn't work: CD folder & ECHO %CD%

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
drinovc.copy
Posts: 6
Joined: 26 Feb 2010 10:38

This doesn't work: CD folder & ECHO %CD%

#1 Post by drinovc.copy » 07 Mar 2010 09:56

I am using this command: CD folder & ECHO %CD%
I need to do this in one line! But it doesn't work? Why not? How can i do this?

Output:
C:\>cd Folder & echo %CD%
C:\ <-THIS IS NOT OK FOR ME - it should be C:\Folder

C:\Folder>

Please help

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: This doesn't work: CD folder & ECHO %CD%

#2 Post by aGerman » 07 Mar 2010 10:50

It doesn't work if you change the directory and show the new directory name in the same line. Why don't you use two lines?

If you work with a batch file there is a trick

Code: Select all

cd Folder &call echo %%CD%%

drinovc.copy
Posts: 6
Joined: 26 Feb 2010 10:38

Re: This doesn't work: CD folder & ECHO %CD%

#3 Post by drinovc.copy » 07 Mar 2010 11:19

I am not using two lines, because i call this command from Delphi.

Code: Select all

CreateProcess(nil, PChar('cmd.exe /C ' + cmdLine), nil, nil, True, 0, nil, PChar(WorkDir), SI, PI);


Is there no other way?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: This doesn't work: CD folder & ECHO %CD%

#4 Post by aGerman » 07 Mar 2010 11:56

You could try to use the delayed expansion of variables.

Code: Select all

cmd /v:on /c "cd Folder&echo !cd!"

Note that it doesn't work without the quotes.
Hope it will work. I have no idea of Delphi.

drinovc.copy
Posts: 6
Joined: 26 Feb 2010 10:38

Re: This doesn't work: CD folder & ECHO %CD%

#5 Post by drinovc.copy » 07 Mar 2010 16:43

It works perfect. I have to call the same function in Delphi, but no problem. First to do it, second to echo new dir ;) Thanks! U really helped me a lot! :wink:

drinovc.copy
Posts: 6
Joined: 26 Feb 2010 10:38

Re: This doesn't work: CD folder & ECHO %CD%

#6 Post by drinovc.copy » 07 Mar 2010 17:55

Another problem. When i open a picture like picture.gif, the program freezes until i close the picture viewer. In linux you can get rid of this by adding & on the end ... but on windows... doesn't work.

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: This doesn't work: CD folder & ECHO %CD%

#7 Post by avery_larry » 08 Mar 2010 16:36

Could do:

cd folder & call echo %%cd%%

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: This doesn't work: CD folder & ECHO %CD%

#8 Post by avery_larry » 08 Mar 2010 16:38

drinovc.copy wrote:Another problem. When i open a picture like picture.gif, the program freezes until i close the picture viewer. In linux you can get rid of this by adding & on the end ... but on windows... doesn't work.

Use the "start" command to start something without waiting for it to finish.

Post Reply