find and delete files csharp

Code Example - find and delete files csharp

                
                        string rootFolderPath = @"C:\\SomeFolder\\AnotherFolder\\FolderCOntainingThingsToDelete";
string filesToDelete = @"*DeleteMe*.doc";   // Only delete DOC files containing "DeleteMe" in their filenames
string[] fileList = System.IO.Directory.GetFiles(rootFolderPath, filesToDelete);
foreach(string file in fileList)
{
    System.Diagnostics.Debug.WriteLine(file + "will be deleted");
//  System.IO.File.Delete(file);
}
                    
                
 

csharp how to delete a file

                        
                                File.Delete(@"C:\Temp\Data\Authors.txt");
                            
                        
 

Related code examples