我想通過這樣來刪除目錄中的所有文件:System.IO.File.Delete無效字符
System.IO.File.Delete(directoriodestino_imagenes + @"\*.*");
其中,directoriodestino_imagenes = "C:\\dcm\\patients\\NAME_LASTNAME\\DCM\\"
。
而且我得到這個:
{ 「路徑中具有非法字符。」}
任何提示我可能做錯了什麼?
我想通過這樣來刪除目錄中的所有文件: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