I need to be able to report on the number of files in each redTAG folder within our 'shared drive'
each main directory in our departments shared drive has a redTAG folder. I need a batch file that will go through all folders and sub folders from a start point that contain 'redTAG' and report back a file count for those directories.
so the following structure:
root - 10 files,
root/redTAG - 2 files,
root/deliveries/ - 4 files,
root/deliveries/redTAG - 5 files,
root/deliveries/help - 4 files,
would report back:
root/redTAG 2,
root/deliveries/redTAG 5
code provided was my last successful attempt at any analysis of the folders etc.
@Echo off&SetLocal EnableExtensions EnableDelayedExpansion
(Echo Folders #Sub #Files ##Sub ##Files
FOR /D %%G in (*) DO (
PUSHD "%%G"
Set /A "Sub#=Files#=0,SUB##=Files##=0"
Set "Folders=%%~G "
FOR /F %%H in ('dir /a-d /b 2^>NUL^|find /C /V "" ') DO Set Files#=%%H
FOR /F %%I in ('dir /ad /b 2^>NUL^|find /C /V "" ') DO Set Sub#=%%I
if !Sub#! gtr 0 (
FOR /F %%H in ('dir /a-d /b /S 2^>NUL^|find /C /V "" ') DO Set Files##=%%H
FOR /F %%I in ('dir /ad /b /S 2^>NUL^|find /C /V "" ') DO Set Sub##=%%I
Set /A "Files##-=Files#,Sub##-=Sub#"
)
Set "Sub#= !Sub#!"
Set "Files#= !Files#!"
Set "Sub##= !Sub##!"
Set "Files##= !Files##!"
Echo !Folders:~,15! !Sub#:~-7! !Files#:~-7! !Sub##:~-7! !Files##:~-7!
POPD
)) > "count.txt"
start count.txt
any of my subsequent attempts have met with failure and hit the back of the bin. I don't need the export to a file but it helps. Some of this code was inherited from a previous colleague who wasn't great at annotation or help