Bot to delete old files

Hi all, I am building a bot which will read file locations from an excel file and then go to those locations and delete any file older than 30 days. If the files are younger than 30 days, it should stop processing and move to the next location. I’ve stored the file location from the excel in an array and was wondering what the best way is to proceed with deleting them and what would be the syntax be ?

Regards
Anived

Hi,

The following workflow will delete files which is written by 30 days ago in specific folder from worksheet

oldFiles = System.IO.Directory.GetFiles(row("Folder").ToString()).Where(Function(f) System.IO.File.GetLastWriteTime(f) <Today.AddDays(-30)).ToArray()

Hope this helps you.

Regards,

1 Like

Thank you, just wanted to check something else as well. The excel has a column which will say if the folder in that location needs to be deleted or the files or both older than 30 days and in some cases the retention days can be different for each location. Shall I use switch to determine action based on no of retention days and if I need to delete both the folder or file or just them individually ?

Hi,

Basically, it’s better to set these condition in excel sheet in advance, then check them and branch to proper process for them. We can use Switch activity, If activity and/or dictionary etc. for it.

Regards,

1 Like

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