System.IO.File.Delete无效字符
问题描述:
我想通过这样来删除目录中的所有文件:System.IO.File.Delete无效字符
System.IO.File.Delete(directoriodestino_imagenes + @"\*.*");
其中,directoriodestino_imagenes = "C:\\dcm\\patients\\NAME_LASTNAME\\DCM\\"
。
而且我得到这个:
{ “路径中具有非法字符。”}
任何提示我可能做错了什么?
答
这是通配符。您无法使用Delete方法删除多个文件。您可能需要删除整个文件夹(请参阅http://msdn.microsoft.com/en-us/library/fxeahc5f(v=vs.110).aspx上的删除文件夹方法),或者只是逐个删除它们。例如。像在Deleting multiple files with wildcard
答
实际上可以删除文件夹中的文件。这是我如何做到的。
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);
从ONLINE REFERENCE引用:'path:要删除的文件的名称。通配符不支持.' – 2014-08-29 00:05:16