0

I use command :

dir D:\ /b /A:D-H

and output is for example:

  • Photos
  • Wallpapers
  • My Personal Data

and.. I want to set varialeble on this folders as:


set SOMEFOLDER=folder1


set SOMEFOLDER2=folder2

and ect..

How can I do this?

2
  • By folder1 and folder2 do you mean e.g. Photos and Wallpapers respectively? Commented Mar 14, 2013 at 9:51
  • Consider reading this. Commented Mar 14, 2013 at 10:22

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.