Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

WAD endlocal not restoring the directory stack or the CWD on drives

Sep
70
1
setlocal
echo C:\
C:\
echo D:\
D:\
echo E:\a
E:\a
pushd c:\windows
pushd d:\proclog
pushd e:\logs
endlocal
echo C:\
C:\
echo D:\proclog
D:\proclog
echo E:\logs
E:\logs
dirs
C:\
C:\Windows
D:\proclog
 
Hello mdlawler - just an aside and not about your question. You may look to enclose your console output in code blocks. Select three "dots" and choose code, paste in your console text, and it is usually much easier to read in a post.
 
Hello mdlawler - just an aside and not about your question. You may look to enclose your console output in code blocks. Select three "dots" and choose code, paste in your console text, and it is usually much easier to read in a

Hello mdlawler - just an aside and not about your question. You may look to enclose your console output in code blocks. Select three "dots" and choose code, paste in your console text, and it is usually much easier to read in a post.
I have not found a good way to do this from the keyboard using my screen reading software yet, but will do so if I figure it out.
 
I always type the code/endcode tags myself, these, without the spaces: [ code ] and [ /code ]. And there are [ icode ] and [ /icode ] (again no spaces) for inline code; I usually select text with the keyboard and choose those from the dropdown (...) menu.
 
I always type the code/endcode tags myself, these, without the spaces: [ code ] and [ /code ]. And there are [ icode ] and [ /icode ] (again no spaces) for inline code; I usually select text with the keyboard and choose those from the dropdown (...) menu.
Thanks Vince, I'll try those the next time.
 
@mdlawler

I see no bug here. After your endlocal command you manually changed the dirs ... so all seems ok.

Or in other words if you would place the endlocal at the end it should be restored (works here).

PS: Microsoft Windows 10 Pro x64 [19045.4412] [22H2] [de-CH] TCMD 32.10.21 x64
 
Last edited:
As @mdlawler said, it doesn't work.

Code:
v:\> type dstack.btm
dirs
setlocal
pushd d:\tc29
pushd d:\tc30
pushd d:\tc31
pushd d:\tc32
endlocal
dirs

v:\> dstack.btm
TCC: V:\dstack.btm [1]  Directory stack empty
V:\
D:\tc29
D:\tc30
D:\tc31
 
And it does work at the command line.

Code:
v:\> dirs
TCC: Directory stack empty

v:\> setlocal

v:\> pushd d:\tc29

d:\tc29> pushd d:\tc30

d:\tc30> pushd d:\tc31

d:\tc31> pushd d:\tc32

d:\tc32> endlocal

v:\> dirs
TCC: Directory stack empty
 
This isn't a straightforward issue. The problem is (of course) CMD, which does not save & restore the directory stack. I originally had TCC saving & restoring the directory stack, and got complaints / bug reports from users saying it broke their CMD batch files. (In the case of a SETLOCAL at the command prompt, CMD behavior isn't an issue because CMD doesn't support that.)

CMD is actually even messier than at first glance, because it restores the original directory on an ENDLOCAL, but ignores the directory stack.

Since I get bug reports either way, I'm going to disable it by default (for CMD compatibility) and enable it only when requested (with a SETLOCAL or ENDLOCAL option).
 
Back
Top
[FOX] Ultimate Translator
Translate