问题描述
如果 frompath =C:\\ progfiles \\ mobileapp \\ ES-GL \\ A.DLL
和 topath =C:\\ progfiles \\ mobileapp \\ ES-GL \\ A.DLL
我想从 frompath
文件复制到 topath
。
如果 topath
不存在,那么目录和子目录必须获得创建和文件A.DLL必须复制从 frompath
到 topath
。我使用C#.NET Compact Framework的。
I want to copy file from frompath
to topath
.
If topath
does not exist, then the directories and sub directories must get created and the file a.dll must copy from frompath
to topath
. I am using c# .net Compact Framework.
推荐答案
我觉得你是System.IO命名空间之后。使用File.Copy可以提供解决方案。而Directory.Exists /创建可以使目录不存在。
I think you are after the System.IO namespace. Using File.Copy can provide the solution.And Directory.Exists / create can make the directory is not existing.
var fileName = "tmp.txt";
var from = @"c:\temp\" + fileName;
var to = @"c:\temp\1\";
if (!Directory.Exists(to))
Directory.CreateDirectory(to);
File.Copy(from, to + fileName);
您可以去的FileInfo以及。 (另外,在System.IO命名空间)
You can go for FileInfo aswell. (Also in the System.IO namespace)
var file = new FileInfo(@"c:\temp\tmp.txt");
var to = @"c:\temp\1\";
if (!Directory.Exists(to))
Directory.CreateDirectory(to);
file.CopyTo(to + file.Name);
这篇关于从一个路径复制到另一个文件路径在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!