Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy file to a different directory

Tags:

c#

.net

file

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

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.

like image 470
networkingNoob Avatar asked Sep 18 '11 17:09

networkingNoob


People also ask

How do you copy all the files from a directory to another directory?

Copying Directories with cp Command To copy a directory, including all its files and subdirectories, use the -R or -r option. The command above creates the destination directory and recursively copy all files and subdirectories from the source to the destination directory.

How do I copy a file from one folder to another in Windows?

Users may also press the Ctrl + C shortcut key, or in Windows Explorer, click Edit at the top of the window and choose Copy. Open the destination folder, right-click an empty space in the folder, and choose paste. Or, in the menu bar at the top, click File, choose Edit, then choose Paste.

How do I copy a file to another file in Linux?

To copy files and directories use the cp command under a Linux, UNIX-like, and BSD like operating systems. cp is the command entered in a Unix and Linux shell to copy a file from one place to another, possibly on a different filesystem.

What command is used to copy files and directories?

The cp Command cp stands for copy. This command is used to copy files or group of files or directories. It creates an exact copy of a file on a disk with different file name.


1 Answers

string fileToCopy = "c:\\myFolder\\myFile.txt"; string destinationDirectory = "c:\\myDestinationFolder\\";  File.Copy(fileToCopy, destinationDirectory + Path.GetFileName(fileToCopy)); 
like image 181
Funkyhead Avatar answered Oct 06 '22 00:10

Funkyhead