Solved

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

Posted on 2004-07-30
2
1,364 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 125 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now