I have a folder by name Uk inside that folder I have folders like 04-Dec-2023
03-Dec-2023
02-Dec-2023
01-Dec-2023
30-Sep-2023
29-Sep-2023
ABC-123
Def-678
I need to delete last 3days folder and the AVC folder and Def folder must not get deleted
Hi @hanviprebday ,
Have you tried for each folder in folder, then check name of them ?
or you can call them as list of folder then use for each
regards,
Use Directory.GetFiles to get all files from a folder
Use For each for iteration
Use If Activityin that
Condition:
(Path.GetFileName(item).Equals(dateMinus1) Or Path.GetFileName(item).Equals(dateMinus2) Or Path.GetFileName(item).Equals(dateMinus3)) And Not (Path.GetFileName(item).Equals(“ABC-123”) Or Path.GetFileName(item).Equals(“Def-678”))
Directory.GetFiles(“yourFolderPath”).Where(Function(x)CDate(new System.IO.FileInfo(x).CreatedDate)>Now.AddDays(-3) and CDate(new System.IO.FileInfo(x).CreatedDate)<Now).ToArray
Note: It will delete the all the folder created in last 3 days and for the current date folder also.
** You can modify this to your requirement also.
Set the “Path” property to the path of the “Uk” folder.
Add a “For Each” activity and connect the output of the “Get Folders” activity to the “Collection” property.
Inside the “For Each” activity, add a “Filter DataTable” activity.
Connect the “CurrentRow” property from the “For Each” activity to the “DataTable” property of the “Filter DataTable” activity.
Set the “Filter Expression” property to “CreationTime >= '” & DateTime.Now.ToString(“yyyy-MM-dd”) & " - 3" & “'”. This will filter out folders older than three days.
Delete filtered folders:
Add a “Delete Folder” activity inside the “Filter DataTable” activity.
Connect the “OutDataRow” property from the “Filter DataTable” activity to the “Path” property of the “Delete Folder” activity.
Protect “ABC-123” and “Def-678” folders:
Add an “If” activity inside the “For Each” activity.
Set the “Condition” property to “CurrentRow.Name = ‘ABC-123’ OR CurrentRow.Name = ‘Def-678’”.
If the condition is true, add an “Assign” activity inside the “If” activity.
In the “Assign” activity, set a variable to indicate that the current folder is protected.