我是靠谱客的博主 冷傲往事,这篇文章主要介绍C#复制文件代码,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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,
那就可以用

复制代码
1
2
File.Move(FileOldPath,FileNewPath) 或者File.Copy(FileOldPath,FileNewPath)
注意的是这里的路径是文件夹路径+文件名,可以用Path.Combine()来实现
----------------------------------
一般是先复制,再删除~
复制代码
1
2
3
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#复制文件代码内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部