如何从一个特定的文件夹删除所有文件? [英] How to delete all files from a specific folder?

查看:105
本文介绍了如何从一个特定的文件夹删除所有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我保存在一个特定的文件夹中的文件在运行时。过了一段时间,我想以编程方式删除它们。如何从一个特定的文件夹中删除所有文件?


解决方案

 的String []文件路径= Directory.GetFiles(@C:\MyDir\); 
的foreach(在文件路径字符串文件路径)
File.Delete(文件路径);

或者在单行:

  Array.ForEach(Directory.GetFiles(@C:\MyDir\),File.Delete); 


I save files in a specific folder at run time. After some time, I want to delete them programmatically. How do I delete all files from a specific folder?

解决方案

string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
foreach (string filePath in filePaths)
File.Delete(filePath);

Or in a single line:

Array.ForEach(Directory.GetFiles(@"c:\MyDir\"), File.Delete);

这篇关于如何从一个特定的文件夹删除所有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆