【问题标题】:System.IO.File.Delete invalid charactersSystem.IO.File.Delete 无效字符
【发布时间】:2014-08-29 00:02:13
【问题描述】:

我正在尝试通过这样做来删除目录中的所有文件:

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

在哪里,directoriodestino_imagenes = "C:\\dcm\\patients\\NAME_LASTNAME\\DCM\\"

我明白了:

{"路径中有非法字符。"}

任何提示我可能做错了什么?

【问题讨论】:

  • 引自在线参考:path: The name of the file to be deleted. Wildcard characters are not supported.

标签: c# file-io invalid-characters


【解决方案1】:

这是通配符。您不能使用 Delete 方法删除多个文件。您要么需要删除整个文件夹(查看http://msdn.microsoft.com/en-us/library/fxeahc5f(v=vs.110).aspx 的删除文件夹方法),要么只需将它们一一删除。例如。比如Deleting multiple files with wildcard

【讨论】:

    【解决方案2】:

    实际上可以删除文件夹中的文件。这是我的做法。

     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 );
    

    【讨论】:

      猜你喜欢
      • 2017-02-02
      • 2011-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多