Need to count files in a changing folder

May 19, 2010 at 07:12:39
Specs: Windows XP
I have found the script to count the unhidden files in a folder:
dir "C:\" /b /a-d-h |find /v /c "::"

But I need to count the files in a folder with yesterday's date on it, and this changes every day. We run a backup program, and I need to verify that it has worked and created a certain number of files.

Today's folder name would be xx-2010-05-18, and tomorrow's will be xx-2010-05-19, and the next day 2010-05-20, and so on. (Today is 05/19)

Can I chdir to the latest folder, perhaps? Is this possible in a dos batch file? Or do I need something more robust?

Susan Cannon

See More: Need to count files in a changing folder

Report •

May 19, 2010 at 08:09:12
[1] Forget DOS

[2] I don't think I'd test a backup by counting files.

@echo off & setLocal EnableDELAYedeXpansion

set /a N=0
for /f "skip=1 tokens=* delims= " %%a in ('dir/b/ad/o-n') do (
pushd %%a && goto :OK

for /f "tokens=* delims= " %%a in ('dir/b/a-d') do set /a N+=1

echo !N! files

Helping others achieve escape felicity


Report •

May 19, 2010 at 08:10:23
for /f %%a in ('dir /ad/od/b') do set chdir=%%a
cd %chdir%


Report •

May 19, 2010 at 08:27:51
Assuming the xx-YYYY-MM-DD are stored in the root and generated daily

@echo off
for /F "delims=" %%j in ('dir "C:\??-????-??-??" /B /AD-H /O-D') do (pushd %%j & goto :DONE)
dir  /B /A-D-H | find /V /C ""

Report •

Related Solutions

May 20, 2010 at 05:50:56
Thanks guys!!

The verification is only a quick way to double check that it ran at all. We have other program-specific tools to ensure that it ran correctly and contains all the pertinent data. We've been running it 3 years now, and the internal tools do just fine.

Every now and then, though, something happens to our network and the whole process (run via a series of batch files) goes kerfluey. Since this is all done in the background at night, we might not notice that it didn't complete correctly until a week or so later. This script is just to give us a quick note to say "all is well, no need to check further."

I appreciate all your great help!! many thanks to you.

(By the way, my grandfather's name was Ivo!!! I thought it was unique! It's good to see another one.)


Susan Cannon

Report •

May 20, 2010 at 08:14:25
Since your grandfather's time the name Ivo was not copyright protected as I was named Ivo from MY grandfather's name.

Ivo Luigi Bertani - Milano (Italy)

Report •

Ask Question