Skip navigation

JSI Tip 5150. How do I receive e-mail when a new file arrives in a folder?

If you need to be notified when a file arrives in a folder, schedule NewFile.bat to start when the computer starts.

NewFile.bat uses BLAT freeware to e-mail the notification, and a Sleep alternative to wait 5 minutes before re-checking the folder.

You will need to modify the folder path from C:\folder, and the recipient's e-mail address.

NewFile.bat contains:

@echo off
setlocal
REM Modify the folder path
cd /d c:\folder
if not exist filelist.txt @echo ZZZZZZ_EOF.ZZZ>filelist.txt
:again
copy filelist.txt filelist.old
del /q filelist.txt
if exist filelist.new del /q filelist.new
for /f "Tokens=*" %%f in ('dir /b /a-d *.*') do @echo "%%f">>filelist.txt
findstr /L /I /V /B /G:filelist.old  filelist.txt>>filelist.new 
set sent=N
for /f "Tokens=*" %%n in (filelist.new) do call :new %%n
REM Sleep 5 minutes
@ping -301 Times 127.0.0.1>nul
goto again
:syntax
@echo Syntax: newfile folder
endlocal
goto :EOF
:new
if "%sent%" EQU "Y" goto :EOF
if /i %1 EQU "ZZZZZZ_EOF.ZZZ" goto :EOF
if /i "%~n1" EQU "filelist" goto :EOF
REM Modify the recipient
blat filelist.new -to [email protected] -s "New files." 
set sent=Y
For a commercial monitor (and much more), see OpalisRobot.



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish