C#中如何复制一个文件,粘贴到指定文件夹? 10
4个回答
展开全部
使用FileInfo.CopyTo即可。
c# code如下:
FileInfo f = new FileInfo("file1");
f.CopyTo("file2");
注:file1和file2更换为对应的路径即可。
c# code如下:
FileInfo f = new FileInfo("file1");
f.CopyTo("file2");
注:file1和file2更换为对应的路径即可。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
private void CopyDirectory(String source, String destination)
{
try
{
DirectoryInfo info = new DirectoryInfo(source);
FileSystemInfo[] sysInfos = info.GetFileSystemInfos();
foreach (FileSystemInfo fsi in info.GetFileSystemInfos())
{
string destName = Path.Combine(destination, fsi.Name);
//if file ,then copy it
if (fsi is System.IO.FileInfo)
{
string sourceName = Path.Combine(source, fsi.Name);
try
{
//just in case the destination is readonly
if (File.Exists(destName))
{
new FileInfo(destName).IsReadOnly = false;
}
File.Copy(fsi.FullName, destName, true);
}
}
}
}
}
{
try
{
DirectoryInfo info = new DirectoryInfo(source);
FileSystemInfo[] sysInfos = info.GetFileSystemInfos();
foreach (FileSystemInfo fsi in info.GetFileSystemInfos())
{
string destName = Path.Combine(destination, fsi.Name);
//if file ,then copy it
if (fsi is System.IO.FileInfo)
{
string sourceName = Path.Combine(source, fsi.Name);
try
{
//just in case the destination is readonly
if (File.Exists(destName))
{
new FileInfo(destName).IsReadOnly = false;
}
File.Copy(fsi.FullName, destName, true);
}
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
FileInfo.CopyTo
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询