Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between in doing file copy/delete and Move

What is difference between

  1. Copying a file and deleting it using File.Copy() and File.Delete()
  2. Moving the file using File.Move()

In terms of permission required to do these operations is there any difference? Any help much appreciated.

like image 590
Bhaskar Avatar asked Jul 08 '11 08:07

Bhaskar


People also ask

Which is best copy or move?

On unix, on moves that don't cross filesystem boundaries, mv does not copy the data: it just updates the inode database in various directories. This is much faster than cp on large files. Further, using mv across filesystem boundaries just silently invokes a copy and delete mechanism. So I think you should prefer mv .

Is moving files faster than copying?

The quality of the target drive can play a role in the speed. Newer drives—depending on the type of port they use—allow for faster data transfer. But all in all, you shouldn't see a difference in speed when copying files on the same drive or outside of it.

Do you copy or move files or folders?

Copy and paste files Select the file you want to copy by clicking on it once. Right-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 .

How we can copying moving and deleting a files?

There are a few ways you can move or copy a file or folder. Drag and Drop: You can move a file or folder from one folder to another by dragging it from its current location and dropping it into the destination folder, just as you would with a file on your desktop.


2 Answers

File.Move method can be used to move the file from one path to another. This method works across disk volumes, and it does not throw an exception if the source and destination are the same.

You cannot use the Move method to overwrite an existing file. If you attempt to replace a file by moving a file of the same name into that directory, you get an IOException. To overcome this you can use the combination of Copy and Delete methods

like image 194
Pranay Rana Avatar answered Sep 28 '22 04:09

Pranay Rana


Performance wise, if on one and the same file system, moving a file is (in simplified terms) just adjusting some internal registers of the file system itself (possibly adjusting some nodes in a red/black-tree), without actually moving something.

Imagine you have 180MiB to move, and you can write onto your disk at roughly 30MiB/s. Then with copy/delete, it takes approximately 6 seconds to finish. With a simple move [same file system], it goes so fast you might not even realise it.

(I once wrote some transactional file system helpers that would move or copy multiple files, all or none; in order to make the commit as fast as possible, I moved/copied all stuff into a temporary sub-folder first, and then the final commit would move existent data into another folder (to enable rollback), and the new data up to the target).

like image 28
Sebastian Mach Avatar answered Sep 28 '22 03:09

Sebastian Mach