Counting Classes of Files in Subfolder Hierarchy

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
lneidorf
Posts: 2
Joined: 03 Mar 2017 05:58

Counting Classes of Files in Subfolder Hierarchy

#1 Post by lneidorf » 03 Mar 2017 06:02

Hi there.

I have a recurring task that is quite simple, but requires a lot of manual steps. I'm hoping to automate it.

On a network drive (which I do map), I have a file structure that looks like this:
PARENT FOLDER\
--TEXT\
--IMAGES\
--NATIVES\

I've been trying to write a script that does the following:
1. Generate a count of the files in each subfolder. I need seepage counts for each of the subfolders I've listed above.
2. Generate a list of filenames for the 0KB .txt files in the TEXT subfolder
3. Output to two text file reports, one with counts and the other a list of the 0kb text files by name only.

Each of the subfolders I listed above contains a series of subfolders (e.g. TEXT\01\ etc). So I need this script to be recursive and not include any of the subfolders in the counts or list of 0kb files.

Seems so simple, yet I can't seem to crack this.

Thanks!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Counting Classes of Files in Subfolder Hierarchy

#2 Post by aGerman » 03 Mar 2017 11:59

Save this file in PARENT FOLDER

Code: Select all

@echo off &setlocal

>"count.txt" (
  for %%i in ("TEXT" "IMAGES" "NATIVES") do (
    for /f %%j in ('dir /a-d /b /s %%i 2^>nul^|find /c /v ""') do echo %%i %%j
  )
)

>"zero.txt" (for /f "tokens=1*" %%i in ('robocopy "TEXT" NULL /l /s /ndl /xx /nc /njh /njs /fp /np') do if %%i==0 echo %%j)

Make sure there is no subfolder with name NULL in PARENT FOLDER.

Steffen

lneidorf
Posts: 2
Joined: 03 Mar 2017 05:58

Re: Counting Classes of Files in Subfolder Hierarchy

#3 Post by lneidorf » 04 Mar 2017 09:05

Steffen,

Thank so much! That's fantastic.

Post Reply