I have som problem with my code...
Im trying to generate variables using a FOR-IN-DO.
Code: Select all
@ECHO OFF
REM -- This .bat should count all subfolders of the folders specified in the
REM -- in the "TARGET_FOLDER_LIST".
REM -- The sub-routine "countAllFolders" shall generate a unique counter-variable
REM -- for each Folder using a "For In Do".
REM --
REM -- After the counting, the generated counter-variable should be ECHO:ed
SET WORK_PATH=%CD%
SET TARGET_FOLDER_LIST=(Folder1 Folder2 Folder3)
SET SOURCE_PATH=%CD%
FOR %%f IN %TARGET_FOLDER_LIST% DO (
SET /A COUNTER_%%f=0
ECHO %SOURCE_PATH%\%%f
call :countAllFolders "%SOURCE_PATH%\%%f" "%%f"
REM ------------------ Here is where I get problem --------------------
ECHO COUNTER_%%f
)
GOTO :eof
:countAllFolders
FOR /R %1 %%i IN (.) DO SET /A COUNTER_%2+=1
GOTO :eof
It all works great untill I try to ECHO on the generated variable inside the first FOR-IN-DO
This:
Code: Select all
ECHO COUNTER_%%f
Will only get me the output "COUNTER_Folder[X]"
And this:
Code: Select all
ECHO %COUNTER_%%f%
Will only get me the output "ECHO is off"
If I add this to my code:
Code: Select all
ECHO %COUNTER_Folder1%
ECHO %COUNTER_Folder2%
ECHO %COUNTER_Folder3%
The output will show a correct count of the subfolders in each Folder.
But my problem is that I need to get the output without specifying the variable-names in advance.
Does anyone have any idea how I should modify my code in order to for it to work properly?