File watcher/ monitor batch script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sri2002
Posts: 4
Joined: 20 May 2013 21:43

File watcher/ monitor batch script

#1 Post by sri2002 » 22 Jun 2013 22:38

Hi
I am looking to write a batch script and I am kinda new. There are like 35 folders and each folder will receive files daily, so I want to monitor all folder if file received daily or not. files can be identified by file name which has date in it but some of them date format is different. Below is the script I tried but it does not work. I want to write the missing file to a log file and finally that log file should be emailed to me. I schedule to run this thru job scheduler daily. Your help is appreciated.

@echo off

set "YYYY=%date:~12,2%"
set "YY=%date:~10,4%"
set "MM=%date:~7,2%"

set "Source=D:\Customer\files"

echo %date% > D:\Customer\files\%YYYY%-%MM%-%DD%-Logfile.txt


IF not exist "%Source%\ABCD\Received\ABC_%YYYY%%MM%%DD%.txt" (echo "ABC_%YYYY%%MM%%DD%.txt does not exist >> %YYYY%-%MM%-%DD%-Logfile.txt")

IF not exist "%Source%\DEFC\Received\DEF_%YYYY%%MM%%DD%.txt" (echo "DEF_%YYYY%%MM%%DD%.txt does not exist >> %YYYY%-%MM%-%DD%-Logfile.txt")

IF not exist "%Source%\FGHI\Received\EFG_%YYYY%%MM%%DD%.txt" (echo "EFG_%YYYY%%MM%%DD%.txt does not exist >> %YYYY%-%MM%-%DD%-Logfile.txt")

.
.
.
.
.
.
.
.

(Thinking to call a VB Script to email attachment, let me know if any batch script available to email log file)

exit


Thanks in advance

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: File watcher/ monitor batch script

#2 Post by foxidrive » 22 Jun 2013 23:20

This should work on XP Pro and higher. There are batch files to email - you can google for it.

Code: Select all

@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set dt=%%a
set datestamp=%dt:~0,8%
set timestamp=%dt:~8,6%
set YYYY=%dt:~0,4%
set MM=%dt:~4,2%
set DD=%dt:~6,2%
set HH=%dt:~8,2%
set Min=%dt:~10,2%
set Sec=%dt:~12,2%

set "Source=D:\Customer\files"
set "log=D:\Customer\files\%YYYY%-%MM%-%DD%-Logfile.txt"
>"%log%" echo %date%

for %%a in (

"%Source%\ABCD\Received\"
"%Source%\DEFC\Received\"
"%Source%\FGHI\Received\"

) do (
for /f "delims=" %%b in ('dir /a-d /b "%%~a\*_%YYYY%%MM%%DD%.txt" ^| find /c /v "" ') do (
if %%b EQU 0 >>"%log%" echo %%a - *_%YYYY%%MM%%DD%.txt files not found
)
)


sri2002
Posts: 4
Joined: 20 May 2013 21:43

Re: File watcher/ monitor batch script

#3 Post by sri2002 » 23 Jun 2013 11:36

It worked, Thanks foxidrive. Really appreciate your help

Post Reply