Monitor folder

Welcome Forums General PowerShell Q&A Monitor folder

Viewing 3 reply threads
  • Author
    Posts
    • #197069
      Participant
      Topics: 1
      Replies: 1
      Points: 15
      Rank: Member

      I have a script that monitors a folder and it’s subfolders.  It is used by the ftp server as a landing location for when we receive ftp files.  The script sends an email to the recepients that a new file has been created in the folder.  The script works, but It sends an email for every file that was copied to the location.  I only want it to send 1 email to the recepients if a file was created in the last 6 hours.  This way if they ftp more than 1 file in the last 6 hours, then only 1 email goes out.  How can i modify my script to do this?

      • This topic was modified 8 months, 2 weeks ago by kvprasoon. Reason: code formatting
    • #197084
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP
    • #197090
      Participant
      Topics: 15
      Replies: 1761
      Points: 3,167
      Helping Hand
      Rank: Community Hero

      The solution posted is made specifically for ‘real-time’, every 6 hours is actually more straight-forward. It looks like all of the emails are going to the same email thread? If you have different emails based on filenames or something to that effect, you can do something like this:

      The files look like this:

      The hours can be added or you can implement a process to move the files or flip an archive bit and then you are just getting all files that are not flipped which would work if the script errored out you could run it 15 hours later and it would just email all non-Archived files. The script could just be run as a scheduled task.

    • #197201
      Participant
      Topics: 1
      Replies: 1
      Points: 15
      Rank: Member

      Rob, thanks for the examples…this is very helpful and gives me a good starting point.  I will be sending an email to several people depending on the folder name, as each folder is for a different client.  If the client uploads 10 files in the last 6 hours, then i want to send out only 1 email confirming that the files were ftp to the folder.  I was using the filesystemwatcher to monitor any new files in the folders…but that was sending an email out for each file that was added to the folder.

Viewing 3 reply threads
  • The topic ‘Monitor folder’ is closed to new replies.