Questions tagged [copy]

To copy is to create a duplicate of an object without destroying the original. Commonly seen in text editors that will let you copy some text and paste it somewhere else.

In computing, copy is related both to the command by which a duplicate of a specified entity is made, both in terms of its definition and content, as well as the resulting duplicate itself.

In terms of abstracted use, 'copy' such as when performing a cut-copy-paste operation via a graphical user interface, is an interface metaphor based on the physical procedure used in manuscript editing to create a page layout.

11278 questions
3702
votes
21 answers

How to copy files

How do I copy a file in Python?
Matt
  • 84,419
  • 25
  • 57
  • 67
3343
votes
14 answers

How do I copy a folder from remote to local using scp?

How do I copy a folder from remote to local host using scp? I use ssh to log in to my server. Then, I would like to copy the remote folder foo to local /home/user/Desktop. How do I achieve this?
Slasengger
  • 33,707
  • 3
  • 14
  • 10
914
votes
23 answers

How do I copy an object in Java?

Consider the code below: DummyBean dum = new DummyBean(); dum.setDummy("foo"); System.out.println(dum.getDummy()); // prints 'foo' DummyBean dumtwo = dum; System.out.println(dumtwo.getDummy()); // prints…
Veera
  • 32,532
  • 36
  • 98
  • 137
769
votes
25 answers

Fastest way to duplicate an array in JavaScript - slice vs. 'for' loop

In order to duplicate an array in JavaScript: Which of the following is faster to use? Slice method var dup_array = original_array.slice(); For loop for(var i = 0, len = original_array.length; i < len; ++i) dup_array[i] = original_array[i]; I…
Marco Demaio
  • 33,578
  • 33
  • 128
  • 159
753
votes
31 answers

What is the difference between a deep copy and a shallow copy?

What is the difference between a deep copy and a shallow copy?
David Locke
  • 17,926
  • 9
  • 33
  • 53
641
votes
19 answers

Is there a function to make a copy of a PHP array to another?

Is there a function to make a copy of a PHP array to another? I have been burned a few times trying to copy PHP arrays. I want to copy an array defined inside an object to a global outside it.
vfclists
  • 19,193
  • 21
  • 73
  • 92
622
votes
29 answers

Copy the entire contents of a directory in C#

I want to copy the entire contents of a directory from one location to another in C#. There doesn't appear to be a way to do this using System.IO classes without lots of recursion. There is a method in VB that we can use if we add a reference to…
Keith
  • 150,284
  • 78
  • 298
  • 434
544
votes
7 answers

Why updating "shallow" copy dictionary doesn't update "original" dictionary?

While reading up the documentation for dict.copy(), it says that it makes a shallow copy of the dictionary. Same goes for the book I am following (Beazley's Python Reference), which says: The m.copy() method makes a shallow copy of the items…
user225312
  • 126,773
  • 69
  • 172
  • 181
519
votes
5 answers

Dockerfile copy keep subdirectory structure

I'm trying to copy a number of files and folders to a docker image build from my localhost. The files are like this: folder1/ file1 file2 folder2/ file1 file2 I'm trying to make the copy like this: COPY files/* /files/ However, all…
user1220022
  • 11,167
  • 19
  • 41
  • 57
430
votes
16 answers

Standard concise way to copy a file in Java?

It has always bothered me that the only way to copy a file in Java involves opening streams, declaring a buffer, reading in one file, looping through it, and writing it out to the other steam. The web is littered with similar, yet still slightly…
Peter
  • 29,498
  • 21
  • 89
  • 122
403
votes
11 answers

Make copy of an array

I have an array a which is constantly being updated. Let's say a = [1,2,3,4,5]. I need to make an exact duplicate copy of a and call it b. If a were to change to [6,7,8,9,10], b should still be [1,2,3,4,5]. What is the best way to do this? I tried a…
badcoder
  • 3,624
  • 5
  • 32
  • 33
375
votes
10 answers

How do I copy items from list to list without foreach?

How do I transfer the items contained in one List to another in C# without using foreach?
ratty
  • 13,216
  • 29
  • 75
  • 108
345
votes
4 answers

How can I create a copy of an object in Python?

I would like to create a copy of an object. I want the new object to possess all properties of the old object (values of the fields). But I want to have independent objects. So, if I change values of the fields of the new object, the old object…
Roman
  • 124,451
  • 167
  • 349
  • 456
338
votes
8 answers

Copy tables from one database to another in SQL Server

I have a database called foo and a database called bar. I have a table in foo called tblFoobar that I want to move (data and all) to database bar from database foo. What is the SQL statement to do this?
RyanKeeter
  • 5,939
  • 7
  • 32
  • 40
322
votes
16 answers

How to copy a row and insert in same table with a autoincrement field in MySQL?

In MySQL I am trying to copy a row with an autoincrement column ID=1 and insert the data into same table as a new row with column ID=2. How can I do this in a single query?
Navdroid
  • 4,453
  • 7
  • 29
  • 47
1
2 3
99 100