[SOLVED] Batch File Folder List

Spazz_1219

Reputable
Jul 3, 2016
11
0
4,510
So, I have a pretty niche request. I'm looking for a way to declare a list of folders as a variable. (Like how in linux I can use holder, and then call it later as $holder.)
Unfortunately I don't need the list of subfolders or files. ONLY the main directory of folders.

My hope is to have something where I can do something along the lines of:
Code:
set list="directory"
echo %list%
 
Last edited:
Solution
ok,so to create such list of folders
Code:
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /D %%A IN ("C:\Documents\Games\*") DO (SET LIST=!LIST!"%%~fA\";)
SETLOCAL DISABLEDELAYEDEXPANSION
that will pretty much create variable which will contain list of folders inside C:\Documents\Games

echo %LIST% will show u whats inside

u can use FOR /? for help with loops

Spazz_1219

Reputable
Jul 3, 2016
11
0
4,510
That should only list off the folders within that directory and not their subfolders/files correct?
Essentially folders and files will be added/removed from this directory over time. Instead of manually updating a list each time, I'd prefer to simplify the process and have the batch file automatically read it off and assign a variable I can call later.
 
Last edited:

Spazz_1219

Reputable
Jul 3, 2016
11
0
4,510
"list" in your case is just replacement for folder location (path to folder)
its not a list with files and subfolders
Yeah that's not entirely what I'm looking for.
I'm trying to pull a list of folders at a directory, without listing subfolders or files.
For example:
C:\Documents\Games\
Would be incorrect as a listing, as it only gets to the directory. Instead I'd like it to output:
C:\Documents\Games\AmericanTruckSimulator; C:\Documents\Games\Arma3; C:\Documents\Games\Borderlands2;

This way, if I call this via a parameter inside a batch file, I can supplement a list of folder locations as just a single variable. Instead of having to manually make a file, list the folders in the file, then calling the file.
 
ok,so to create such list of folders
Code:
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /D %%A IN ("C:\Documents\Games\*") DO (SET LIST=!LIST!"%%~fA\";)
SETLOCAL DISABLEDELAYEDEXPANSION
that will pretty much create variable which will contain list of folders inside C:\Documents\Games

echo %LIST% will show u whats inside

u can use FOR /? for help with loops
 
Solution

Spazz_1219

Reputable
Jul 3, 2016
11
0
4,510
ok,so to create such list of folders
Code:
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /D %%A IN ("C:\Documents\Games\*") DO (SET LIST=!LIST!"%%~fA\";)
SETLOCAL DISABLEDELAYEDEXPANSION
that will pretty much create variable which will contain list of folders inside C:\Documents\Games

echo %LIST% will show u whats inside

u can use FOR /? for help with loops

Perfect! I couldn't figure out to use delayed expansion. Honestly had no clue it was there and it didn't exactly seem like it was needed, but that makes a lot more sense now! Thank you!