-4

I'm trying to delete all files in a directory by doing this:

System.IO.File.Delete(directoriodestino_imagenes + @"\*.*");

Where, directoriodestino_imagenes = "C:\\dcm\\patients\\NAME_LASTNAME\\DCM\\".

And I get this:

{"Illegal characters in path."}

Any hints what I may be doing wrong?

Sam
  • 7,252
  • 16
  • 46
  • 65
Matimont
  • 739
  • 3
  • 14
  • 33

2 Answers2

2

It's the wildcard character. You cannot delete multiple files using Delete method. You either need to delete the whole folder (look at the Delete folder method at http://msdn.microsoft.com/en-us/library/fxeahc5f(v=vs.110).aspx) or just remove them one by one. E.g. like in Deleting multiple files with wildcard

Community
  • 1
  • 1
Petr Podhorsky
  • 701
  • 3
  • 5
1

Actually it is possible to delete Files in a folder. Here is how I do it.

 string directory = @"C:\File Downloader\DownloadedFile\";
 string[] file = Directory.GetFiles(directory); // get all files in the folder.
 foreach (string fileName in file )
 File.Delete(fileName );
Kuriyama Mirai
  • 867
  • 5
  • 17
  • 37