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.
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.
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.
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.
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.
string fileToCopy = "c:\\myFolder\\myFile.txt"; string destinationDirectory = "c:\\myDestinationFolder\\"; File.Copy(fileToCopy, destinationDirectory + Path.GetFileName(fileToCopy));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With