如何在C#中删除文件? [英] How to delete file in c#?

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

问题描述

我在删除C#中的文件时遇到问题
在我的代码中

I have a problem with deleting the file in C#
In my code

if (System.IO.File.Exists(destination))
{
    System.IO.File.Delete(file);
}
System.IO.File.Copy(source,destination);
System.IO.File.Delete(source);


在我的代码中,问题是
创建新文件时,目标文件已经存在,它将复制到目标文件夹中,名称为destination

文件大时发生问题.

问题是文件删除未完成,并且文件复制已开始...
:(....

对不起,我的英语....


任何帮助都将足够....

谢谢..


In my code the problem is
destination file already exist when i create a new file it will copied into destination folder with the name as destination

problem occurred when file size is big..

problem is file delete is not completed and file copy is start......
:(....

sorry for my english....


Any Help will sufficient....

Thanks..

推荐答案

只需使用File.Move:
Just use File.Move:
if (System.IO.File.Exists(destination))
{
    System.IO.File.Delete(file);
}
System.IO.File.Move(source,destination);


http: //www.dotnetperls.com/file-delete [ ^ ]
http://sandeep-aparajit.blogspot.com/2008/04/how-to-delete-file-in-c.html [
http://www.dotnetperls.com/file-delete[^]
http://sandeep-aparajit.blogspot.com/2008/04/how-to-delete-file-in-c.html[^]


http://sandeep-aparajit.blogspot.com/2008/04/how-to-delete-file-in-c.html [ http://rhondatipton.net/2007/12/29/copydelete-files-in-c / [ ^ ]
http://www.dotnetperls.com/file-delete[^]
http://sandeep-aparajit.blogspot.com/2008/04/how-to-delete-file-in-c.html[^]
http://rhondatipton.net/2007/12/29/copydelete-files-in-c/[^]


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

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