set variable multiple value [SOLVED]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
deniscalanca
Posts: 14
Joined: 26 Oct 2017 11:30

set variable multiple value [SOLVED]

#1 Post by deniscalanca » 12 Jun 2024 08:03

Hi, I'm trying to create a batch file script to save all the folders within C:\Users that contain student name in a variable, I managed to get to the point where I return the folder name but I couldn't save the name of more than a folder in the same variable.

EX: C:\Usuários\Aluno1
C:\Usuários\Aluno2
C:\Usuários\Aluno3
C:\Usuários\Aluno4

I would like the variable to return

profile_delete=Student1 Student2 Student3 Student4

for /f %%a in ('"dir /b C:\Users |findstr /i aluno"') do (
echo %%a
pause
)

Could someone help me?
Last edited by deniscalanca on 25 Jun 2024 08:09, edited 1 time in total.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: set variable multiple value

#2 Post by Squashman » 12 Jun 2024 11:09

Code: Select all

@echo off
setlocal enabledelayedexpansion
set "profile_delete="
for /f "delims=" %%a in ('dir /b C:\Users ^|findstr /i aluno') do (
set "profile_delete=%%a !profile_delete!"
)
echo %profile_delete%

deniscalanca
Posts: 14
Joined: 26 Oct 2017 11:30

Re: set variable multiple value

#3 Post by deniscalanca » 12 Jun 2024 11:20

thank you very much

Post Reply