Batch Files That Counts By Date

I need to write a batch file that will accept a date parameter and count the number of files in a directory for that date.  Any help is appreciated.
sherbug1015Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve KnightIT ConsultancyCommented:
Well an easy way which may or not do what you want is:
@echo off
if "%1"=="" echo usage %0 dd/mm/yyyy & goto :eof
dir  | find "%1" /C

If you want to find everything edited in October then you could use 10/2008 as your date for instance and if you want files in all subdirs at /s to the dir command.

Steve
0
sherbug1015Author Commented:
This does not seem to be working.  I have attached a batch file that I am working from.  Rather than copy the files to another directory, I just want to count the files that match and write the results to the output file.  
@echo off
cls
SET LOG=GetFiles.out
 
REM ### Get the date
SET YYYYMMDD1=%1
SET YYYYMMDD2=%2
SET YYYYMMDD3=%3
SET YYYYMMDD4=%4
SET YYYYMMDD5=%5
 
 
if "%1"=="" GOTO CMDERROR
 
echo %YYYYMMDD1% >%LOG%
echo %YYYYMMDD2% >>%LOG%
echo %YYYYMMDD3% >>%LOG%
echo %YYYYMMDD4% >>%LOG%
echo %YYYYMMDD5% >>%LOG%
 
 
 
REM ### Copy yesterday's files to the working directory
if NOT "%1"=="" copy c:ABC\A*_%YYYYMMDD1%*.txt . >>%LOG%
 
 
 
echo ###########################
echo # All Done!               #
echo #                         #
echo ###########################
 
GOTO END
 
:CMDERROR
echo #
echo # Please pass the date as a command line argument (YYYYMMDD)
echo #
 
:END
pause

Open in new window

0
Steve KnightIT ConsultancyCommented:
Doyu just want a count of the files that match this:  c:ABC\A*_%YYYYMMDD1%*.txt

In which case use

dir c:ABC\A*_%YYYYMMDD1%*.txt | find /v /c "xxxxx"

to get that into a variable try

for /f %% a in ('dir c:ABC\A*_%YYYYMMDD1%*.txt ^| find /v /c "xxxxx"') do echo There are %%a files in c:ABC\A*_%YYYYMMDD1%*.txt  >>%log%

(I think) Haven't tested!

Steve
0
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

sherbug1015Author Commented:
I incorporated your solution into my file and rather than counting the number of files, it is counting the number of characters in the filename.

For example if I have a directory called c:\abc.  In that directory I have three files named
ACA_20081112_1456.txt
ACA_20081113_1234.txt
ACA_20081113_5678.txt

I want to count all the files like A*_20081113*.txt
I would like the batch file to return 2

Is there a way I can do that?  I have attached the code with your solution incorporated.  It returns an 8, which is incorrect.

cls
SET LOG=GetFiles.out
 
REM ### Get the date
SET YYYYMMDD1=%1
SET YYYYMMDD2=%2
SET YYYYMMDD3=%3
SET YYYYMMDD4=%4
SET YYYYMMDD5=%5
 
 
if "%1"=="" GOTO CMDERROR
 
echo %YYYYMMDD1% >%LOG%
echo %YYYYMMDD2% >>%LOG%
echo %YYYYMMDD3% >>%LOG%
echo %YYYYMMDD4% >>%LOG%
echo %YYYYMMDD5% >>%LOG%
 
 
 
REM ### Copy yesterday's files to the working directory
if NOT "%1"=="" dir c:new\A*_%YYYYMMDD1%*.txt | find /v /c "xxxxx"
for /f %%a in ('dir c:new\A*_%YYYYMMDD1%*.txt ^| find /v /c "xxxxx"') do echo There are %%a files in c:ABC\A*_%YYYYMMDD1%*.txt . >>%log%
 
 
 
 
 
echo ###########################
echo # All Done!               #
echo #                         #
echo ###########################
 
GOTO END
 
:CMDERROR
echo #
echo # Please pass the date as a command line argument (YYYYMMDD)
echo #
 
:END
pause

Open in new window

0
Steve KnightIT ConsultancyCommented:
There is no way it should count the characters....?  What does the dir line output when it shows it in the "if not "%1"=="" line...

Do you really mean c:new.... btw and not c:\new, i.e. at the moment it will work on the subdir new of the dir with the batch in?

Steve
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sherbug1015Author Commented:
I got it working.  Thanks.
0
Steve KnightIT ConsultancyCommented:
Don't forget to select an answer if it helped and grade it appropriately... and always helpful to post what worked in the end for someone else watching.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.