How does copy and paste for large files work

17,352

Clipboard doesn't have to hold entire file. When you copy a file (or files), only its path is put into the clipboard. It's also marked as a file - clipboard keeps track of its content's type, like plain text, formatted text, file, image, Word text etc. This is why you can't for example open up an image in Paint, press Ctrl+C and then paste it into a directory - because you have copied a picture, and directories hold files, not pictures.

When you paste a compatible content (i.e. file(s) and/or folder(s)) into a directory, some application will handle the copying/moving operation. By default it will be the explorer process (the same one that's responsible for displaying Start menu and all file explorer windows), but some apps may replace it.[1]

What happens now depends on what you're doing:

  • If you're moving a file to another directory on the same partition, it won't be physically moved on the disk, only its path will be updated[2].
  • If you're moving a file to another partition, it will be split into chunks of the same size[3] and those will be copied one by one, then the original file will be deleted. Too small chunks will slow down the process, too big chunks will consume more memory.
  • Exactly the same will happen when you're copying a file (no matter if it's the same partition or not), except that the original file won't be deleted.
  • Writing to an external storage (like USB drives) doesn't work exactly like that[4] and I'm not sure what exactly happens then. My guess is that it's not a continuous chunk-by-chunk process, but something else happens every few chunks (buffer-related?). If anybody knows something about this, then feel free to edit.

Annotations:

[1]. For example TeraCopy, which is a nice advanced copy window replacement.

[2]. Physical file structure on the hard disk doesn't resemble the directory structure - it's flat and all hierarchy information is stored in a separate part of the partition. How it's exactly done depends on filesystem (for example see MFT). That information block holds all the information about file locations etc. So when you move a file inside one partition, there's no need to move it physically - only the path information has to be updated.

[3]. Not literally, nothing will be split on the hard disk. The program that handles the copying process will work like there are multiple separate chunks, but the original file will be untouched. It's purely virtual.

[4]. You can see it when using TeraCopy: the "predicted progress" doesn't work like on fixed drives, instead the "real progress" catches up with it, then "predicted progress" is expanded and so on. Explorer's default copy window has USB hiccups too.

Share:
17,352

Related videos on Youtube

Sundeep
Author by

Sundeep

Updated on September 18, 2022

Comments

  • Sundeep
    Sundeep almost 2 years

    I am curious to know how computers execute "copy" and "paste" of large folders. I've read that copy and paste of text between different processes or same process is achieved by saving the content into RAM and then copying it from there to destined location.

    So, how does computer instructions flow while copying a folder of say 10 GB on a machine which has 2 GB RAM and 4 GB max virtual memory. Is file copy is different from text copy.

    I think it's basic question but any links or insights appreciated.

    • Dennis
      Dennis over 11 years
      The clipboard doesn't actually contain the contents of the folder, just the folder's location.
    • Brad Patton
      Brad Patton over 11 years
      I think it would also depend on the OS. Is your question specifically about Windows?
    • Dennis
      Dennis over 11 years
      Copying a file can be done with a fixed amount of RAM: 1. Read, e.g., 1 MB from the source file. 2. Write to the destination file. 3. Repeat. The copying process is handled, by default, by Windows Explorer.
  • Mavromatis Lozay
    Mavromatis Lozay over 11 years
    "This is why you can't for example open up an image in Paint, press Ctrl+C and then paste it into a directory - because you have copied a picture, and directories hold files, not pictures." You can with Directory Opus. But your point stands.
  • Matt
    Matt about 6 years
    TeraCopy is incredibly slow, around 3x slower than file transfers via Windows Explorer, at least currently on Windows 10 pro. Robocopy that ships with Windows 10 can copy files via multiple concurrent threads and significantly speed up the transfer process. So does FastCopy (external app)