将文件复制到不同的目录不同、文件、目录

2023-09-04 08:03:23 作者:除了堅強ャ別無選擇づ

我的工作,我想一些文件在一个目录复制到第二个已经存在的目录中的项目。

我无法找到一个方法来简单地从一个文件夹复制到另一个。我能找到将文件复制到一个新的文件或目录到一个新的目录。

我有我的程序设定,现在是我复制的文件,并把它留在同一个目录的方式,然后移动该副本到我想要的目录。

编辑:

谢谢大家。所有答案的工作。我意识到我做错了什么,当我设定的目标路径我没有添加一个文件名。一切正常,现在,感谢您的超快速响应。

解决方案

  File.Copy(@someDirectory \ someFile.txt,@otherDirectory \ someFile.txt);
 

工作正常。

I am working on a project where I want to copy some files in one directory to a second already existing directory.

VS生成项目时,有些文件无法复制到输出目录的解决办法

I can't find a way to simply copy from one folder to another. I can find copy file to a new file, or directory to a new directory.

The way I have my program set up right now is I copy the file and leave it in same directory, then move that copy to the directory that I want.

Edit:

Thanks everyone. All of your answers worked. I realized what I did wrong, when i set the destination path I didn't add a filename. Everything works now, Thanks for the super speedy responses.

解决方案

File.Copy(@"someDirectory\someFile.txt", @"otherDirectory\someFile.txt");

works fine.