Check for file date and type

Hi all, I have x n o no files in one location. I need to check if date modified is equal to current date and if it is then I need to check for a certain type and if it that type’s available then get that file.

At present I have a for each loop over that directory and an if condition saying if date modified is same as current date then do stuff. The problem with this is since the for loop is there when the bot loops through the directory and if there are other files available whose modified date isn’t the same as today date it goes to the else section. I want the bot to look in the directory ,find the file whose last modified date is same as today’s date and then check for its type and perform actions on it. How can I do this. Please advise.

Hi @Anived_Mishra ,

  1. Use assign activity :
    getFiles =directory.GetFiles(FolderPath)*
    FolderPath= Path of folder where your files are present
  2. Use for each activity
    Inside body of for each use if condition activity
    item.ToLower.Contains(“.pdf”)/item.ToLower.Contains(“.xlsx”)* etc.
    if yes then proceed
  3. Or you can use Path.GetExtension(GetFiles) to get the extensions
  4. for checking DateTime modification = IO.File.GetLastWriteTime(“C:\test.txt”)

Change “C:\test.txt” to your filepath from for each
then check it in an if condition.

Thanks & Regards,
Shubham Dutta

1 Like

Hi @Shubham_Dutta, the issue with this is, if file type isn’t .pdf inside the for each, it will just go to the else section . I want it to move to the next item and check again until that file is found.

Hi @Anived_Mishra ,
With if else condition also you can proceed to next files inside a for each.
I am sending you a sample workflow which has sample files inside “Folders” for your reference. (134.4 KB)

I hope this will help you.

Thanks & Regards,
Shubham Dutta

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