我使用命令:
dir D:\ /b /A:D-H
并输出例如:
和..我想在此文件夹中设置可变为:
设置SOMEFOLDER = folder1
设置SOMEFOLDER2 = folder2
等等..
我该怎么做?
答案 0 :(得分:1)
您可以在与文件夹相同的目录中使用以下批处理文件:
@echo off
setlocal enabledelayedexpansion
set num=0
for /d %%i in (*) do set /a num+=1&set SOMEFOLDER!num!=%%i
echo SOMEFOLDER1 = %SOMEFOLDER1%
echo SOMEFOLDER2 = %SOMEFOLDER2%
pause
如果您需要在不同目录中使用批处理文件或想要更改某些选项,请改为使用:
@echo off
setlocal enabledelayedexpansion
set num=0
for /f "tokens=*" %%i in ('dir D:\ /b /a:D-H') do set /a num+=1&set SOMEFOLDER!num!=%%i
echo SOMEFOLDER1 = %SOMEFOLDER1%
echo SOMEFOLDER2 = %SOMEFOLDER2%
pause