gpt4 book ai didi

batch-file - MS-Win-CMD PushD/PopD 如何工作以及为什么不在 "For/f"-Loop 中

转载 作者:行者123 更新时间:2023-12-03 11:13:41 30 4
gpt4 key购买 nike

在我一次又一次找不到答案后,我编写了这些脚本:

<!-- : first Line of "JustPopdBack.cmd"-Script (a CMD+Script for Windows)
@echo off %debug%
setLocal enableExtensions

:: Copyleft 2017 Markus Merkle (aka Mäx) - Licence: GNU-GPLv3
:: ----------------------------------------------------------------------------
:: Cause it seems stupid to make a short Script long just for Right
:: of the Author, so the Licence-Text is not embeded in this Script.
:: !!! Please have a look on <http://www.gnu.org/licenses/>
:: if you still don't know the GNU-GPLv3.
:: ----------------------------------------------------------------------------
:: This is just a free and open TestScript
:: Feel free to used or modify but please mark this work (how as done).
:: -----------------------------------------------------------------------------
title JustPopdBack-Test
color 0a %= cause I like LightGreen on Black =%
echo.
echo. Just a Test-Script for PushD and PopD Command
echo.
echo. To use it please Enter some Directorys first
echo. Don't shy to use diffrent Drives (C:\ or D:\ etc. )
echo. ...and feel free to use the TAB-Key then...
echo. Lets PushD in this Dir and after just Enter Nothing Popd out.
::******************************************************************************
:dLoop for UserQuest and Pushd in
echo.
set "NxtDir="
set /P "NxtDir=NextDir? :\> "
if defined NxtDir (PushD %NxtDir% & goTo dLoop)
::------------------------------------------------------------------------------
echo.
echo. Lets see the PushD History
pushD
echo. now try again with "For /F"-Loop a PopD Back.
for /f %%a in ('pushD') do (echo %%a && PopD)
echo.
echo This don't work - did you know why?
timeOut -1
:*******************************************************************************
:PopDback that will work
PopD && Echo. Uh I PopD'd - let's'ee PushD now: && PushD && goTo PopDback
:: but I don't like that - can you help to make me happy ?
--------------------------------------------------------------------------------
timeout -1
color
exit /b %= That the End of this Script =%
:: Thnx to all my Teachers
:: ...but the realy ones not the called & most have just 60 Minutes for me...

我希望你明白我为什么写这个脚本,也希望大家给我很多评论,这样我们就可以找出这里或那里出了什么问题......(嘿,不在我的脑海中 - 我希望:-)

我这篇文章的目标是一个作品

for /f %a in ('PushD') do PopD

最佳答案

for/F 在新的 cmd.exe 上下文中启动命令。
因此,pushd 会在那里执行,然后上下文将被关闭。
新cmd.exe中的pushd根本不影响父上下文。
因此 popd 不会恢复 Pushd。

如果你只想弹出所有pushd,你可以使用循环

@echo off
setlocal EnableDelayedExpansion
pushd C:\windows\
pushd c:\windows\system32

:popd_all
echo #: !cd!
popd && goto popd_all

关于batch-file - MS-Win-CMD PushD/PopD 如何工作以及为什么不在 "For/f"-Loop 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42593863/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com