[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

compare file timestamp to current date/time and count new files added in last hour

Posted on 2004-07-30
2
Medium Priority
?
1,420 Views
Last Modified: 2008-03-06
I need a script that will compare the timestamp of the files in the folder c:\done to the current date and time and count any new files added.  The count and a description ( example : 5 new files processed for interface a) should be written to a text file that can then be emailed.  Thanks for your help in advance.
0
Comment
Question by:uhsdba
  • 2
2 Comments
 
LVL 30

Expert Comment

by:SteveGTR
ID: 11681259
Try this:

@echo off

setlocal

for /F "tokens=2-4 delims=/ " %%f in ('date /t') do (
 set mm=%%f
 set dd=%%g
 set yy=%%h
)

set yy=%yy:~-2%

set /A cnt=0

set curDate=%mm%/%dd%/%yy%

if exist log.txt del log.txt >NUL

for /F "delims=" %%a in ('dir /a-d /b %1') do call :PROCESS "%%a" %%~ta

echo Total new file(s): %cnt%
echo log.txt contains a list of the new files.

goto :EOF

:PROCESS

if %1==log.txt goto :EOF
if not "%2"=="%curDate%" goto :EOF

set /A cnt+=1

echo %~1 >>log.txt

The batch file accepts an option command line parameter that is the directory where you'd like to check. Example: newfiles c:\

Good Luck,
Steve
0
 
LVL 30

Accepted Solution

by:
SteveGTR earned 375 total points
ID: 11681270
You can suppress the output of the check file statement with this code:

if /I %cnt% GTR 0 echo log.txt contains a list of the new files.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question