c# 删除文件

v_oneforever 2009-03-09 04:44:50
有以下信息:
c盘:
abb(文件夹)
a.doc
a.ab.doc
a.cd.doc
a.txt
b.doc
根据c:\\abb\a 删除所有以a开头doc的文件。

我的思路是用File.Delete
先找到所有所有以a开头doc的文件的完整路径。解析问号之后,.之前的字符。为a。然后把文件给删了
在web上进行。。。但具体调用哪些函数呢



...全文
148 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
v_oneforever 2009-03-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 Guyschaos 的回复:]
引用楼主 v_oneforever 的帖子:
有以下信息:
c盘:
abb(文件夹)
a.doc
a.ab.doc
a.cd.doc
a.txt
b.doc
根据c:\\abb\a 删除所有以a开头doc的文件。

我的思路是用File.Delete
先找到所有所有以a开头doc的文件的完整路径。解析问号之后,.之前的字符。为a。然后把文件给删了
在web上进行。。。但具体调用哪些…
[/Quote]

好了~~~
v_oneforever 2009-03-10
  • 打赏
  • 举报
回复
protected void Button1_Click(object sender, EventArgs e)
{
this.getDefaultLang();
String in_file = Label1.Text.ToString();

int start = in_file.LastIndexOf("\\") + 1;
//int end = dir[i].LastIndexOf(".resx");
string etr = in_file.Substring(start, in_file.Length - start);
String str = in_file.Substring(0, start - 1);

String s = null;

if (this.RadioButtonList1.SelectedValue == "N")
{
for (int i = 1; i < ar_Language.Count; i = i + 2)
{
if (ar_Language[i].ToString() == ddl_language.SelectedItem.ToString())
{
s = ar_Language[i - 1].ToString();
break;
}
}
if (def_Language[0].ToString() ==s)
{
String filePath = in_file + ".resx";
File.Delete(filePath);
}
else
{
string _FilePath = in_file + "." + s + ".resx";
File.Delete(_FilePath);
}
}
else
{
String[] filePath = Directory.GetFiles(str, "*.resx");
for (int i = 0; i != filePath.Length; i++)
{
System.IO.File.Delete(filePath[i]);
}

}


自己写的。。不知是否复杂了一点。。不过能运行出来
睡神在睡觉 2009-03-09
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zgke 的回复:]
string[] _FilePath = System.IO.Directory.GetFiles(@"C:\", "a*.doc");

for (int i = 0; i != _FilePath.Length; i++)
{
System.IO.File.Delete(_FilePath[i]);
}
[/Quote]


这个就没问题了!
深海之蓝 2009-03-09
  • 打赏
  • 举报
回复
先用Directory.GetFiles()取得所有文件
再用File.Delete()删除
zgke 2009-03-09
  • 打赏
  • 举报
回复
string[] _FilePath = System.IO.Directory.GetFiles(@"C:\", "a*.xls");

for (int i = 0; i != _FilePath.Length; i++)
{
System.IO.File.Delete(_FilePath[i]);
}
贫僧又回来了 2009-03-09
  • 打赏
  • 举报
回复
[Quote=引用楼主 v_oneforever 的帖子:]
有以下信息:
c盘:
abb(文件夹)
a.doc
a.ab.doc
a.cd.doc
a.txt
b.doc
根据c:\\abb\a 删除所有以a开头doc的文件。

我的思路是用File.Delete
先找到所有所有以a开头doc的文件的完整路径。解析问号之后,.之前的字符。为a。然后把文件给删了
在web上进行。。。但具体调用哪些函数呢



[/Quote]
这个问题现在还没好?
wuyi8808 2009-03-09
  • 打赏
  • 举报
回复
@"c:\abb\a*.doc"

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧