List directory stack in windows

旧时模样 提交于 2021-02-08 04:39:42

问题


I am trying to list the directories that have been added to the directory stack using the command: pushd

I cannot find any references or command on how to print the directory stack contents.

Any help is appreciated


回答1:


A pushd without parameters outputs the list of the stacked directories.

pushd c:\
pushd windows
pushd help
pushd windows
pushd en-us

pushd

Will output

c:\Windows\Help\Windows
c:\Windows\Help
c:\Windows
c:\
c:\Temp

The latest pushed directory is missing here, but can simply retrieved by %__CD__%.

And there is one more directory (in my case C:\temp), as that will be the directory after the last executed popd.




回答2:


Nice challenge. As already noted, there seems to be no built-in way to get that information, so you need a script to do it step-by-step:

@echo off
setlocal enabledelayedexpansion
set origin=%cd%

rem build a demo stack:
pushd c:\
pushd windows
pushd help
pushd windows
pushd en-us

rem get stack step by step:
set i=0
:loop
  popd && (
    set /a i+=1
    echo !i! --- %cd%
    set "p[!i!]=%cd%"
   ) || (
    goto :TopOfStack
   ) 
goto :loop

:TopOfStack
echo stack empty.
cd %origin%
rem restore stack:
set p[
for /l %%i in (%i%,-1,1) do (
  pushd "!p[%%i]!"
)

Note: see also jeb's answer.



来源:https://stackoverflow.com/questions/50462331/list-directory-stack-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!