I am attempting to write a script that will recursively scan a directory, local files with the \'.Error\' extension, then email a group of people with a list of the files. I am
Break out the project into sections. You stated the following requirements:
To scan every 20 minutes, you can either use a timer yourself or more basic and easier to understand, run the script as a scheduled task to execute every 20 minutes.
To only figure the deltas, you need a way to figure out what the last run was so you can compare it to the new run. The more specific question is, do you want to store every previous run or only the most previous run? If only the most previous run, then just dump the results of the initial run to a importable log file (csv, json, xml, etc.) and then read it on on each subsequent run to compare, and then finally, overwrite. If you want to keep each run indefinitely, you need a way to determine out of all the historical results, which ones were the last run--a timestamp is an easy way to achieve this. Then only grab the results that match the last run's timestamp.
One of the keys to your issue will be, how do you define 'changed'? Is it the existence of a new file/directory at all or is there a possibility of a file that existed before to have it's contents changed? If so, that's a different calculus--do you only want to compare byte size, date changed (a combination of both), or a CRC or hash algorithm? Each will give you a different level of fidelity with different caveats or costs.
As far as the emailing part goes, it looks like you already have that down.