如何将文件从一个目录复制到新目录? [英] How can I copy a file from one directory in to a new directory?

查看:113
本文介绍了如何将文件从一个目录复制到新目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有简单的方法可以将单个文件从一个目录复制到新目录?
我试过了:

Is there any simple way to copy a single file out of one directory to a new one?
I tried this:

Dim path As String = Application.StartupPath + "\Work.xml"
        Dim path2 As String = Application.StartupPath & "\SavedFiles"
        File.Copy(path, path2)


但是然后我收到一条错误消息,说目标文件"C:\ Users \ User \ Desktop \ MyProgram \ MyProgram \ bin \ Debug \ SavedFiles"是目录,而不是文件."
这种方法也不起作用:


But then I receive an error saying "The target file "C:\Users\User\Desktop\MyProgram\MyProgram\bin\Debug\SavedFiles" is a directory, not a file."
This way doesn''t work either:

File.Copy(Application.StartupPath + "\Work.xml", Application.StartupPath + "\SavedFiles")


对于如何将单个文件从一个目录复制到新目录的任何帮助,将不胜感激.


Any help on how to copy a single file from one directory to a new one would be greatly appreciated.

推荐答案

您必须将全名指定为目的地
You have to specify full name as destination
Dim path As String = Application.StartupPath & "\Work.xml"
Dim path2 As String = Application.StartupPath & "\SavedFiles\Work.xml"
File.Copy(path, path2)


这篇关于如何将文件从一个目录复制到新目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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