Question: Can anyone help me correct this batch file? I think the issue is in the for / f statement someplace. The objective is to count

Can anyone help me correct this batch file? I think the issue is in the for /f statement someplace. The objective is to count the files and subdirectories within a specific directory including hidden ones, however NOT to count any of the files in the subdirectories.
setlocal enabledelayedexpansion
echo.
set /p "directory=What directory would you like to check? "
set "fileCount=0"
set "hiddenFiles=0"
set "visibleFiles=0"
set "dirCount=0"
set "hiddenDirs=0"
set "visibleDirs=0"
for /f %%i in ('dir /a /s /b "%directory%"') do (
set "attr=%%~ai"
set /a "fileCount+=1"
if "!attr:~3,1!"=="h"(
set /a "hiddenFiles+=1"
) else (
set /a "visibleFiles+=1"
)
if "!attr:~0,1!"=="d"(
set /a "dirCount+=1"
if "!attr:~3,1!"=="h"(
set /a "hiddenDirs+=1"
) else (
set /a "visibleDirs+=1"
)
)
)
:: Display message with results
echo.
echo There are a total of %fileCount% files in the %directory% directory.
echo Of the %fileCount% files, %hiddenFiles% are hidden and %visibleFiles% are not hidden.
echo.
echo There are a total of %dirCount% directories in the %directory% directory.
echo Of the %dirCount% directories, %hiddenDirs% are hidden and %visibleDirs% are not hidden.
echo.
pause

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!