How can I copy all of the contents in one directory to another with out looping over each file?
Copy and paste filesRight-click and pick Copy, or press Ctrl + C . Navigate to another folder, where you want to put the copy of the file. Click the menu button and pick Paste to finish copying the file, or press Ctrl + V . There will now be a copy of the file in the original folder and the other folder.
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.
Step 1: Click on the first file to be selected. Step 2: Hold down Ctrl and click on all the files that you want to select additionally. Step 2: Press the Shift key and click on the last file. Step 3: You have now selected all files at once and can copy and move them.
In order to copy a directory on Linux, you have to execute the “cp” command with the “-R” option for recursive and specify the source and destination directories to be copied.
You can't. Neither Directory
nor DirectoryInfo
provide a Copy
method. You need to implement this yourself.
void Copy(string sourceDir, string targetDir) { Directory.CreateDirectory(targetDir); foreach(var file in Directory.GetFiles(sourceDir)) File.Copy(file, Path.Combine(targetDir, Path.GetFileName(file))); foreach(var directory in Directory.GetDirectories(sourceDir)) Copy(directory, Path.Combine(targetDir, Path.GetFileName(directory))); }
Please read the comments to be aware of some problems with this simplistic approach.
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