Two primary methods immediately come to mind:
- Start a daemon type script that always sits there running, and it checks, sleeps, checks, sleeps, etc
- Have a script that runs once and checks, and execute it periodically with cron or windows scheduler or whatever you have a vailable on XP.
Assuming you have a scheduling means, I would say the second is the better method -- something isn't always running (your efficiency concern), and it's more robust becuase you don't have to worry about the job getting hung or killed.
Two methods pop to mind for the actual "checking" part, too:
- Check the directory for files created in the last N minutes.
- Keep a state file (maybe look at Cache::FileCache; and also useful related info in the recent best way to keep a simple count? about storing data between runs) that is the last time you ran and what files existed, and compare against that. (or store the last timestamp you checked, and check for files created affter that)
Be sure to reference the
File::Find module as well as the -X and stat sections in the perlfunc manpage.
Update: Here's an actual one-liner solution i used out of a linux crontab once (convenient cause cron takes care of emailing you iff there's output)--this is the shell script wrapping it (I don't necessarily recommend this, but might have some reference value):
# USAGE: touchedCheck filename [minutes]
#
# Exit Value: 0 if file was touched; 1 if not touched.
#
# Will print info about the file iff it changed in the last N minutes.
# Otherwise prints nothing.
#
# Intended for crontab use, such as:
# 0 * * * * touchedCheck /tmp/some_file.txt 60
#
/usr/bin/perl -e '$f=shift;$N=shift||60; printf("%s was changed %d min
+utes ago.\n%s", $f, $x/60.0, `/bin/ls -lart $f`) && exit(0) if ($x =
+(time - (stat($f))[9])) <= 60*$N; exit(1)' $1 $2