Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Selective Copy and overwrite 7 54
Command-line Script 15 71
Batch file to delete a folder 5 71
access denied when running native SQL tool: SQLIOSIM 2 23
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

15 Experts available now in Live!

Get 1:1 Help Now