我正在尝试删除目录中的所有文件:
System.IO.File.Delete(directoriodestino_imagenes + @"\*.*");
其中,directoriodestino_imagenes = "C:\\dcm\\patients\\NAME_LASTNAME\\DCM\\"
。
我明白了:
{“路径中的非法字符。”}
任何提示我可能做错了什么?
答案 0 :(得分:2)
它是通配符。您无法使用Delete方法删除多个文件。您需要删除整个文件夹(查看http://msdn.microsoft.com/en-us/library/fxeahc5f(v=vs.110).aspx处的删除文件夹方法)或者只是逐个删除它们。例如。比如Deleting multiple files with wildcard
答案 1 :(得分:1)
实际上可以删除文件夹中的文件。我就是这样做的。
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 );