Solved how do i set a subfolder as a variable

Microsoft Sql server 2005 developer edit...
July 20, 2011 at 19:03:28
Specs: Windows Server 2003, 8GB
I want to run a batch file that looks for a file in all subfolders of \reports\users until it finds a file called arp230.report. When it finds that file, I want the User's folder name where it found the file to become the variable.
ex.
\reports\users\brian\
\reports\users\bob\arp230.report
\reports\users\bill\

So %username% should = bob...


See More: how do i set a subfolder as a variable

Report •

#1
July 23, 2011 at 12:34:00
✔ Best Answer
Hi

@echo off
cls
call :FindIt arp230.report
exit /b

:FindIt %1
cd\
for /f "tokens=* delims=" %%a in ('dir /s/b ^| find "%~1"') do (
set Found=%%~da%%~pa
)
echo Found=%Found%
for /f "tokens=1-4 delims=\" %%a in ("%Found%") do (
Set User=%%d
)
echo User=%User%
exit /b


Report •
Related Solutions


Ask Question