我是靠谱客的博主 冷傲往事,最近开发中收集的这篇文章主要介绍C#复制文件代码,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

private void Copy()
{
DirectoryInfo dir = new DirectoryInfo("c:\CSS");
CopyDirectorysAndFiles("c:\test", dir);
}
private void CopyDirectorysAndFiles(string dest, DirectoryInfo srcdir)
{
if (dest.LastIndexOf('\') != (dest.Length - 1))
{
dest += "\";
}
string destPath = dest +srcdir.Name + "\";
if (!Directory.Exists(destPath))
{
Directory.CreateDirectory(destPath);
}
FileInfo[] files = srcdir.GetFiles();
foreach (FileInfo file in files)
{
file.CopyTo(destPath + file.Name, true);
}
DirectoryInfo[] dirs = srcdir.GetDirectories();
foreach (DirectoryInfo dirInfo in dirs)
{
CopyDirectorysAndFiles(destPath, dirInfo);
}
} 

 

-----------------------------------
C#拷贝文件原来的文件路径名FileOldPath;
新的文件路径名:FileNewPath,
那就可以用

File.Move(FileOldPath,FileNewPath)
或者File.Copy(FileOldPath,FileNewPath) 
注意的是这里的路径是文件夹路径+文件名,可以用Path.Combine()来实现
----------------------------------
一般是先复制,再删除~
System.IO.File.Move(File, newfile);
System.IO.File.Copy(File, newfile);
System.IO.File.Detele(File); 

转载于:https://www.cnblogs.com/cnaspnet/archive/2009/11/27/1612099.html

最后

以上就是冷傲往事为你收集整理的C#复制文件代码的全部内容,希望文章能够帮你解决C#复制文件代码所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(73)

评论列表共有 0 条评论

立即
投稿
返回
顶部