Date time issue _ delete 7 day old file

I am trying to delete all file which are more than 7 days old. Its not working .
My sequence is below
The file modified format is -
image

Sequence

Hi

Hope the below steps would help you resolve this

  1. Use a assign activity like this

arr_filepath = Directory.GetFiles(“yourfolderpath”)

Where arr_filepath is a variable of type array of string

  1. Now use a FOR EACH activity and pass above array variable as input and change the type argument as string

  2. Inside the loop use a IF activity with condition like this

new System.IO.FileInfo(item).CreationTime > DateTime.Now.AddDays(-7)

If this condition is true it goes to THEN block. Where use a DELETE FILE activity and pass filepath as item.ToString

Cheers @ravindar.singh

Thanks Palaniyappan.
from what I got I am already trying your method. I am deleting files from share point.


1 Like

Atlast with if activity lets not compare with string

Remove .ToString at both end between > symbol

It has to be like comparing datetime and not the strings

Cheers @ravindar.singh

Not sure if this will help. This is my variable type

DriveItemFiles

@Palaniyappan
I found a solution not a great one but it does work lol.
Using split and then converting yo datetime
image

The reason it’s not working is because LastModifiedDateTime is of type DateTimeOffset. You can try to convert it to DateTime first:

DriveItemFiles.LastModifiedDateTime.LocalDateTime < Now.Add(-7)
1 Like

I am getting this error

But I found the solution.

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