I use command :
dir D:\ /b /A:D-H
and output is for example:
and.. I want to set varialeble on this folders as:
set SOMEFOLDER=folder1
set SOMEFOLDER2=folder2
and ect..
How can I do this?
You can use the following for a batch file in the same directory as the folders:
@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
If you need the batch file in a different directory or want to change some options, use this instead:
@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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.