Page 1 of 1

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

Posted: 07 Mar 2010 09:56
by drinovc.copy
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

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

Posted: 07 Mar 2010 10:50
by aGerman
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%%

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

Posted: 07 Mar 2010 11:19
by drinovc.copy
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?

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

Posted: 07 Mar 2010 11:56
by aGerman
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.

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

Posted: 07 Mar 2010 16:43
by drinovc.copy
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:

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

Posted: 07 Mar 2010 17:55
by drinovc.copy
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.

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

Posted: 08 Mar 2010 16:36
by avery_larry
Could do:

cd folder & call echo %%cd%%

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

Posted: 08 Mar 2010 16:38
by avery_larry
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.