gpt4 book ai didi

windows - Windows 中用 FOR 遍历路径变量

转载 作者:可可西里 更新时间:2023-11-01 10:04:10 26 4
gpt4 key购买 nike

我忠实的路径遍历方法不再有效——它将空格视为分隔符。好久没做批处理编程了。
使用 FOR 循环时,唯一允许使用分隔符的是 FOR/F 选项。
我不想创建一个包含路径的临时文件,希望做如下的事情:

C:\Users>for /f "delims=;" %i in %path% do echo %i
C:\Program was unexpected at this time.

C:\Users>for /f "delims=;" %i in (%path%) do echo %i
\Common was unexpected at this time.

C:\Users>for /f "delims=;" %i in 'foo;bar' do echo %i
'foo was unexpected at this time.

最佳答案

@echo off
setlocal EnableDelayedExpansion

for /F "delims=" %%a in (^"!path:^;^=^
% Do NOT remove this line %
!^") do echo %%a

输出示例:

C:\Program Files (x86)\AMD APP\bin\x86_64
C:\Program Files (x86)\AMD APP\bin\x86
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Program Files (x86)\Windows Live\Shared
C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static
C:\Program Files\Bandizip\7z

关于windows - Windows 中用 FOR 遍历路径变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38913232/

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