Page 1 of 1

set variable multiple value [SOLVED]

Posted: 12 Jun 2024 08:03
by deniscalanca
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?

Re: set variable multiple value

Posted: 12 Jun 2024 11:09
by Squashman

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%

Re: set variable multiple value

Posted: 12 Jun 2024 11:20
by deniscalanca
thank you very much