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.

copy
Filter by
Sorted by
Tagged with
3805 votes
21 answers
3.7m views

How to copy files

How do I copy a file in Python?
Matt's user avatar
  • 86.3k
3448 votes
14 answers
3.4m views

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's user avatar
  • 34.8k
926 votes
23 answers
1.5m 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()); // ...
Veera's user avatar
  • 32.9k
783 votes
25 answers
798k views

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 < ...
Marco Demaio's user avatar
753 votes
31 answers
841k 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?
David Locke's user avatar
649 votes
19 answers
574k views

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's user avatar
  • 19.6k
629 votes
29 answers
499k 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 ...
Keith's user avatar
  • 153k
548 votes
6 answers
580k views

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 ...
user1220022's user avatar
  • 11.6k
547 votes
7 answers
324k 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....
user225312's user avatar
  • 129k
430 votes
16 answers
280k views

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 ...
Peter's user avatar
  • 29.6k
410 votes
11 answers
830k 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,...
badcoder's user avatar
  • 3,714
379 votes
10 answers
559k 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?
ratty's user avatar
  • 13.3k
365 votes
8 answers
356k views

why should I make a copy of a data frame in pandas

When selecting a sub dataframe from a parent dataframe, I noticed that some programmers make a copy of the data frame using the .copy() method. For example, X = my_dataframe[features_list].copy() ......
Elizabeth Susan Joseph's user avatar
364 votes
4 answers
417k views

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 ...
Roman's user avatar
  • 128k
343 votes
8 answers
914k 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 ...
RyanKeeter's user avatar
  • 6,029
328 votes
16 answers
670k views

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's user avatar
  • 4,513
313 votes
10 answers
389k 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 ...
David Chang's user avatar
  • 3,131
307 votes
17 answers
698k views

How can I create a copy of an Oracle table without copying the data?

I know the statement: create table xyz_new as select * from xyz; Which copies the structure and the data, but what if I just want the structure?
Andrew's user avatar
  • 13.1k
295 votes
13 answers
147k 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) ==...
deeshank's user avatar
  • 4,426
295 votes
7 answers
154k views

What is the difference between `sorted(list)` vs `list.sort()`?

list.sort() sorts the list and replaces the original list, whereas sorted(list) returns a sorted copy of the list, without changing the original list. When is one preferred over the other? Which is ...
alvas's user avatar
  • 119k
285 votes
19 answers
499k 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-...
HoKy22's user avatar
  • 4,147
278 votes
10 answers
460k views

How to deep copy a list?

After E0_copy = list(E0), I guess E0_copy is a deep copy of E0 since id(E0) is not equal to id(E0_copy). Then I modify E0_copy in the loop, but why is E0 not the same after? E0 = [[1, 2, 3], [4, 5, 6],...
Shen's user avatar
  • 3,041
277 votes
5 answers
166k 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 ...
alexenko's user avatar
  • 3,073
269 votes
23 answers
216k views

How to copy files from 'assets' folder to sdcard?

I have a few files in the assets folder. I need to copy all of them to a folder say /sdcard/folder. I want to do this from within a thread. How do I do it?
Rohith Nandakumar's user avatar
263 votes
6 answers
144k views

How to copy text to clipboard/pasteboard with Swift

I'm looking for a clean example of how to copy text to iOS clipboard that can then be used/pasted in other apps. The benefit of this function is that the text can be copied quickly, without the ...
Garry Law's user avatar
  • 2,976
260 votes
16 answers
374k 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 >...
uclajatt's user avatar
  • 4,193
259 votes
26 answers
235k views

Eclipse copy/paste entire line keyboard shortcut

Anyone know the keyboard shortcut to copy/paste a line into a new line in Eclipse, without having to highlight the entire line? ctrl-alt-down turns my whole screen upside down (I'm on windows). ...
Prabhu's user avatar
  • 13.2k
251 votes
7 answers
167k 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 ...
Mark Bramnik's user avatar
  • 41.1k
241 votes
15 answers
168k 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?
Adolf Dsilva's user avatar
  • 13.7k
239 votes
7 answers
347k views

How to export all data from table to an insertable sql format?

I have a Table (call it A_table) in a database (call it A_db) in Microsoft SQL Server Management Studio, and there are 10 rows. I have another database (call it B_db), and it has a Table (call it ...
victorio's user avatar
  • 6,416
232 votes
13 answers
143k views

How do I copy a hash in Ruby?

I'll admit that I'm a bit of a ruby newbie (writing rake scripts, now). In most languages, copy constructors are easy to find. Half an hour of searching didn't find it in ruby. I want to create a copy ...
Precipitous's user avatar
  • 5,323
229 votes
2 answers
45k 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 ...
Peter Fine's user avatar
  • 2,903
227 votes
4 answers
251k 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 ...
user710818's user avatar
  • 23.8k
216 votes
2 answers
78k views

Copy text to clipboard with iOS

What is the best way to copy text to the iPhone's clipboard in your application? Their docs are sketchy and have way more features than what I want... I just want to set a string as the users ...
tarnfeld's user avatar
  • 26.3k
208 votes
9 answers
170k 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 $...
Nick Stinemates's user avatar
205 votes
5 answers
396k views

Find and copy files

Why does the following does not copy the files to the destination folder? # find /home/shantanu/processed/ -name '*2011*.xml' -exec cp /home/shantanu/tosend {} \; cp: omitting directory `/home/...
shantanuo's user avatar
  • 32k
194 votes
26 answers
279k views

In MySQL, can I copy one row to insert into the same table?

insert into table select * from table where primarykey=1 I just want to copy one row to insert into the same table (i.e., I want to duplicate an existing row in the table) but I want to do this ...
lina's user avatar
  • 1,941
186 votes
3 answers
58k 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 ...
Hexdoll's user avatar
  • 2,046
185 votes
13 answers
365k 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 ...
Fero's user avatar
  • 13.1k
183 votes
14 answers
340k 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 ...
Mono Jamoon's user avatar
  • 4,537
182 votes
34 answers
571k views

Copying files from one directory to another in Java

I want to copy files from one directory to another (subdirectory) using Java. I have a directory, dir, with text files. I iterate over the first 20 files in dir, and want to copy them to another ...
user42155's user avatar
  • 49.3k
181 votes
4 answers
436k views

Copying files to a container with Docker Compose

I have a Dockerfile where I copy an existing directory (with content) to the container which works fine: Dockerfile FROM php:7.0-apache COPY Frontend/ /var/www/html/aw3somevideo/ COPY Frontend/ /var/...
TheDoctor's user avatar
  • 2,442
181 votes
2 answers
88k views

Secret copy to clipboard JavaScript function in Chrome and Firefox?

Update Looks like browsers are starting to support copy natively in JS In the console windows of both Chrome and Firefox on Mac I can execute copy("party in your clipboard!"); and the text gets ...
Mike Grace's user avatar
  • 16.8k
180 votes
4 answers
178k 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 ...
dkv's user avatar
  • 6,980
179 votes
10 answers
367k 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 ...
Ali's user avatar
  • 265k
176 votes
9 answers
418k 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 ...
Surya's user avatar
  • 3,458
172 votes
5 answers
317k 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?
sarsnake's user avatar
  • 27.2k
172 votes
13 answers
529k views

copying all contents of folder to another folder using batch file?

I have a folder: C:\Folder1 I want to copy all the contents of Folder1 to another location, D:\Folder2 How do I do this using a batch file?
SCM's user avatar
  • 2,115
170 votes
8 answers
195k views

C++, copy set to vector

I need to copy std::set to std::vector: std::set <double> input; input.insert(5); input.insert(6); std::vector <double> output; std::copy(input.begin(), input.end(), output.begin()); //...
CrocodileDundee's user avatar
169 votes
6 answers
147k views

Copy file with pathlib in Python

I try to copy a file with pathlib import pathlib import shutil my_file=pathlib.Path('/etc/hosts') to_file=pathlib.Path('/tmp/foo') shutil.copy(my_file, to_file) I get this exception: /home/...
guettli's user avatar
  • 27.5k

1
2 3 4 5
228