-3

Hy,

I have a FilesToDelete.txt file filled with file paths like:

C:\Users\Me\Pics\file01.png
C:\Users\Me\Pics\file03.png
C:\Users\Me\Pics\file15.png
etc...

How can I delete these files with C#? Thanks!

Robee
  • 21
  • 7
  • 1
    Have a look at [File.ReadAllLines()](https://learn.microsoft.com/en-us/dotnet/api/system.io.file.readalllines?view=netframework-4.8) and [File.Delete()](https://learn.microsoft.com/en-us/dotnet/api/system.io.file.delete?view=netframework-4.8) – Brian Rogers Dec 13 '19 at 22:11

1 Answers1

2

Simple process would be to loop over each entry in the text file and delete one at a time.

string fileName = @"C:\file_with_paths_to_delete.txt";
    var files = File.ReadAllLines(fileName);

    foreach(string file in files)
        File.Delete(file);
Jawad
  • 11,028
  • 3
  • 24
  • 37