Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Shell 

Counting Classes of Files in Subfolder Hierarchy

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!
Check if this does the trick. You'll need to set the actual address for you network drive. NOTE: the network drive address should not have a trailing \ and keep the be sure the "" stay in place. I tested this with the local admin share ( \\computername\c$\ ) so your results may vary using an actual network location.

Code
@echo off&setlocal enabledelayedexpansion
REM delayed expansion will allow me to keep the below variable up to date while they run through the loops
REM without delayed expansion, the result would be incorrect because each iteration of the loop would think the
REM variable was the same as when the loop started.
set images=0
set natives=0
set text=0
set "address=[NETWORK DRIVE ADDRESS HERE WITHOUT TRAILING \]"

REM dir with /b bare formating /s recursive /a-d with attribute: no directories

for /f " tokens=* " %%a in ('dir /b/s/a-d "!address!\images"') do (
set /a images=!images!+1
)
for /f " tokens=* " %%a in ('dir /b/s/a-d "!address!\natives"') do (
set /a natives=!natives!+1
)
for /f " tokens=* " %%a in ('dir /b/s/a-d "!address!\text"') do (
set /a text=!text!+1
)

echo total number of images: !images!
echo total number of natives: !natives!
echo total number of text: !text!
echo ----------------------------------------
echo TEXT FILENAMES
for /f " tokens=* " %%a in ('dir /b/s/a-d "!address!\text"') do (
echo %%~nxa
REM n=list filenames x=list extension
)

pause >nul
There's no place like ~/


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by unknown321Aug 25, 2019 01:14 PM 23 630 Aug 25, 2019 01:14 PM
Last Post: 0xDEAD10CC
[C#] by n31ght0Oct 6, 2018 05:35 AM 3 236 Oct 6, 2018 05:35 AM
Last Post: itcorp
[Python] by systxApr 20, 2017 11:20 PM 18 619 Apr 20, 2017 11:20 PM
Last Post: Goodies