11,322 questions
3940
votes
21
answers
4.1m
views
How do I copy a file?
How do I copy a file in Python?
936
votes
23
answers
1.6m
views
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()); // ...
753
votes
31
answers
887k
views
What is the difference between a deep copy and a shallow copy?
What is the difference between a deep copy and a shallow copy?
635
votes
29
answers
525k
views
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 ...
554
votes
7
answers
336k
views
Why updating "shallow" copy dictionary doesn't update "original" dictionary? [duplicate]
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....
419
votes
11
answers
879k
views
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,...
383
votes
10
answers
581k
views
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?
355
votes
8
answers
969k
views
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 ...
324
votes
10
answers
418k
views
Copy files from one directory into an existing directory
In bash I need to do this:
take all files in a directory
copy them into an existing directory
How do I do this? I tried cp -r t1 t2 (both t1 and t2 are existing directories, t1 has files in it) but ...
304
votes
12
answers
163k
views
What is the difference between shallow copy, deepcopy and normal assignment operation?
import copy
a = "deepak"
b = 1, 2, 3, 4
c = [1, 2, 3, 4]
d = {1: 10, 2: 20, 3: 30}
a1 = copy.copy(a)
b1 = copy.copy(b)
c1 = copy.copy(c)
d1 = copy.copy(d)
print("immutable - id(a)==id(a1)", id(a) == ...
301
votes
5
answers
204k
views
Git: copy all files in a directory from another branch
How do I copy all files in a directory from another branch? I can list all of the files in that directory by doing
git ls-tree master:dirname
I can then copy all of the files individually by doing
...
291
votes
19
answers
548k
views
Using scp to copy a file to Amazon EC2 instance? [closed]
I am trying to use my Mac Terminal to scp a file from Downloads (phpMyAdmin I downloaded online) to my Amazon EC2 instance.
The command I used was:
scp -i myAmazonKey.pem phpMyAdmin-3.4.5-all-...
269
votes
16
answers
424k
views
MySQL: Cloning a MySQL database on the same MySql instance
I would like to write a script which copies my current database sitedb1 to sitedb2 on the same mysql database instance. I know I can dump the sitedb1 to a sql script:
mysqldump -u root -p sitedb1 >...
267
votes
7
answers
191k
views
Git copy file preserving history [duplicate]
I have a somewhat confusing question in Git.
Lets say, I have a file dir1/A.txt committed and git preserves a history of commits
Now I need to copy the file into dir2/A.txt (not move, but copy).
I ...
258
votes
15
answers
187k
views
How to clone or copy a list in kotlin
How to copy list in Kotlin?
I'm using
val selectedSeries = mutableListOf<String>()
selectedSeries.addAll(series)
Is there a easier way?
246
votes
4
answers
289k
views
How to copy in bash all directory and files recursive?
I have script:
find ./SourceFolder/ -maxdepth 4 -exec cp -R '{}' ./DestFolder/ \;
SourceDir contains also sub-folders.
Problem that in DestFolder not only all tree, but in up level all another ...
232
votes
2
answers
47k
views
Understanding exactly when a data.table is a reference to (vs a copy of) another data.table
I'm having a little trouble understanding the pass-by-reference properties of data.table. Some operations seem to 'break' the reference, and I'd like to understand exactly what's happening.
On ...
214
votes
9
answers
178k
views
How do I create a copy of an object in PHP?
It appears that in PHP objects are passed by reference. Even assignment operators do not appear to be creating a copy of the Object.
Here's a simple, contrived proof:
<?php
class A {
public $...
203
votes
3
answers
62k
views
Record file copy operation with Git
When I move a file in git using git-mv the status shows that the file has been renamed and even if I alter some portions it still considers to be almost the same thing (which is good because it lets ...
196
votes
4
answers
226k
views
PyTorch preferred way to copy a tensor
There seems to be several ways to create a copy of a tensor in PyTorch, including
y = tensor.new_tensor(x) #a
y = x.clone().detach() #b
y = torch.empty_like(x).copy_(x) #c
y = torch.tensor(x) #d
b ...
190
votes
15
answers
369k
views
How to copy a java.util.List into another java.util.List
I have a List<SomeBean> that is populated from a Web Service. I want to copy/clone the contents of that list into an empty list of the same type. A Google search for copying a list suggested me ...
187
votes
13
answers
377k
views
How to copy data from one table to another new table in MySQL?
I want to copy data from one table to another in MySQL.
Table 1 (Existing table):
aid
st_id
from_uid
to_gid
to_uid
created
changed
subject
message
link
Table 2 (New Table)
st_id
uid
changed
...
185
votes
5
answers
349k
views
Batch file to copy directories recursively
Is there a way to copy directories recursively inside a .bat file? Is an example of this available?
181
votes
10
answers
380k
views
How to copy a file from one directory to another using PHP?
Say I've got a file test.php in foo directory as well as bar. How can I replace bar/test.php with foo/test.php using PHP? I'm on Windows XP, a cross platform solution would be great but windows ...
178
votes
9
answers
446k
views
How to copy file from HDFS to the local file system
How to copy file from HDFS to the local file system . There is no physical location of a file under the file , not even directory . how can i moved them to my local for further validations.i am tried ...