How to delete any files that exist in a folder

I know with using the condition:
Directory.GetFiles(“C:\Users…”, “.”, SearchOption.AllDirectories).Count > 0
I can check if there are any files in the folder.
If there are files existing, what activites can I use to delete all the files in the folder without deleting the folder?

1 Like


Use Delete File Activity to clear all the files one by one from the directory.

lets say I do not know the name of the files.

Array.ForEach(Directory.GetFiles(FolderPath),Sub(x) File.Delete(x))

DeleteMultipleFiles.xaml (5.1 KB)
here is a sample workflow cheers @dvn happy learning!


Hope these steps would help you resolve this
—use a assign activity like this
arr_files = Directory.GetFiles(“yourfolderpath”,”.*”, SearchOption.AllDirectories)**
Where arr_files is a variable of type array of string

—now use a IF conditioning this
arr_files.Count > 0
If true it goes to THEN part or to ELSE
Where in the THEN part we can use FOR EACH activity and pass the above variable as input
—inside the loop use DELETE FILE activity and mention the input as item.ToString

Cheers @dvn

1 Like

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