用分号wmic循环分隔

时间:2014-04-26 02:53:51

标签: batch-file

以变量

获取驱动器
LogicalDisk = "c:\d:\"

现在我希望驱动器以分号分隔;

喜欢LogicalDisk = "c:\;d:\;e:\;f:\"

@echo on
setlocal enabledelayedexpansion

    for /f "tokens=2 delims==" %%d in ('wmic logicaldisk where "drivetype=3" get name /format:value')  do (
    set "LogicalDisk=!LogicalDisk!%%d\"
    )
    echo %LogicalDisk%

endlocal
pause

1 个答案:

答案 0 :(得分:0)

或者

for /f "tokens=2 delims==" %%d in ('wmic logicaldisk where "drivetype=3" get name /format:value')  do (
 set "LogicalDisk=!LogicalDisk!%%d\;"
)
set"LogicalDisk=%LogicalDisk:~0,-1%"
echo %LogicalDisk%

for /f "tokens=2 delims==" %%d in ('wmic logicaldisk where "drivetype=3" get name /format:value')  do (
set "LogicalDisk=!LogicalDisk!%%d\"
)
set"LogicalDisk=%LogicalDisk:\=\;%"
set"LogicalDisk=%LogicalDisk:~0,-1%"
echo %LogicalDisk%