I'm trying to get the total size of a directory (_sourceFolder) (including subdirectories) into one variable (_localvar) with the code below.
I tried to enable setlocal enabledelayedexpansion but it didn't help.
@echo off
set _sourceFolder="D:\data"
dir/A-D /S %_sourceFolder%|for /F "tokens=*" %%a in ('FIND "bytes"') do set _localvar=%%a
echo %_localvar%
However the subcommand set _localvar=%%a is not performed, instead I see in the stdout some output like:
C:\>set _localvar=1 File(s) 27.686 bytes
C:\>set _localvar=1 File(s) 27.686 bytes
C:\>set _localvar=3272 File(s) 1.812.083.061 bytes
C:\>set _localvar=1 File(s) 27.686 bytes
C:\>set _localvar=3275 File(s) 1.812.166.119 bytes
C:\>set _localvar=0 Dir(s) 7.431.806.976 bytes free
But %_localvar% is still empty/not set. I expect to have %_localvar% filled/set as displayed by the output on stdout.
Does anybody see the error I made here?