Your question is not entirely clear, but here is how you can collect names of all the files you are deleting. However, please take the time to review all the other comments here, there is a lot of valid points you should really consider.
private List<string> EmptyFolderContents(string folderName)
{
var deletedFiles = new List<string>();
foreach (var file in Directory.GetFiles(folderName))
{
try
{
File.Delete(file);
deletedFiles.Add(file);
}
catch (Exception excep)
{
System.Diagnostics.Debug.WriteLine(excep);
}
}
return deletedFiles;
}
The you need to feed the list into your list box. I assume that part is clear since you posted the code relevant to deleting the files, not the UI-related code.