Monitor Files in a Folder

Hi @jack.chan and everyone

I have a situation where I have a file which gets pasted into a folder location everyday. What I want to do is send out a mail if the file is not present today, in addition to that if the file is not present consecutively for 2 days I want to send out another email regarding it.

How to achieve this

Hi @Ishan_Shelke check this linq:

Directory.GetFiles(YourDirectory).AsEnumerable().Where(function (x) File.GetLastWriteTime(x).Date >= today.adddays(-2))

@Ishan_Shelke
whats the name of the file? is there a fixed format?

Yes, it starts with MER everytime

Hi @Ishan_Shelke ,

A Check on the file is present or not could be done with the following :

Directory.GetFiles("YourFolderPath","MER*").Any

The above would result true if any file of the same format is present in the folder specified.

The Consecutive days part needs more clarification, Is the Process being Scheduled for those two days, If so, there wouldn’t be a need to handle that, but if the Schedule Frequency is more and you would only want to send mails twice if not received, then an Asset could be used to mark the count. Also, are different emails to be sent ?

Case 1 :

  1. Initial Run → File Not Present → Retrieve Asset value, value<2,Update Asset to 1 (Initially was 0) → Send Mail
  2. Second Run → File Not Present → Retrieve Asset value, value<2, Update Asset to 2 → Send Mail
  3. Third Run → File Not Present → Retrieve Asset value, value<2 (Results to False), Nothing to perform

Maybe the Reverting condition i.e Changing the Asset value back to 0 would need to be understood if that could be put in the Third Run’s condition i.e Value Greater than 2. But we do not know the full requirements yet, so do analyse and maybe provide us some more insights on the process and we’ll try to help you further.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.