0

Is it true to say (on Windows and Unix\Linux\OS X) that renaming a file or directory is just an alias for moving?

e.g.

  1. Are there any side effects to either which are not present on the other?
  2. Does 'rename' actually 'move' move under the hood?

Is there a way I can prove\disprove this?

  • Can you share with us where you heard this? – Robert Harvey May 6 '15 at 17:31
  • I didn't hear it, I'm just wondering if there is a difference as it seems to me that the behaviour of rename is the same as moving to a different place within its directory. I wanted to know how I can prove\disprove whether this assumption is correct. – BanksySan May 6 '15 at 17:41
  • @BanksySan - How do you distinguish between "rename" and "move"? (They're interchangeable words on many systems.) – David Hammen May 6 '15 at 22:57
  • @DavidHammen That's my point, in my mind they are the same thing. I wanted to know if this assumption would hold up to scrutiny. – BanksySan May 7 '15 at 9:05
  • @BanksySan - The reason I asked was that there a distinction can be made. There's a big difference between changing the contents of folders/directories but leaving the file untouched versus copying the file to a new location, deleting it from the old location, and changing the contents of folders/directories to reflect those actions. – David Hammen May 7 '15 at 10:55
4

Is there a way I can prove\disprove this?

No, because

  • Different operating systems do things differently.
  • Different kinds of renames/moves can be conceptually different acts:

    • Renaming/moving a file within the same directory,
    • Renaming/moving a file from one folder/directory to another on the same logical device,
    • Renaming/moving a file from one logical device to another, and
    • Renaming/moving a file from one physical device to another.

On most common modern systems, renaming/moving a file within the same logical device is a simple matter of deleting the reference to the file object from the original location and adding a reference to the file object in the target location. The contents of the file are not touched.

This is impossible when "moving" across physical devices. The contents of the file to be moved don't exist on the target device. The contents have to be copied. How moving across logical devices depends on the operating system's concept of a logical device.

2

The extra options supported by Win32 MoveFileEx function provide a good overview and explanation of the similarities and differences between renaming and moving.

When moving files across volumes, a copy (followed by delete) is performed.

From the perspective of an ordinary computer user, when one wants to perform a rename, one would expect the computer to prevent this from overwriting an existing file of the same name.

Whereas copying and moving would offer a choice of cancelling, auto-renaming, or replacing (overwriting).

Note that this is from a user's perspective, not from a programmer's perspective. However, the API must support additional flags so that the programmer can implement the user's expectations.

In summary, due to conventions inherited from the days of MS-DOS, a "rename" is perceived to be less destructive (other than being renamed) than a "move", even though the distinction no longer has any relevance to the underlying mechanism (the file system) unless the operation spans different file systems.

Unix and Linux had been designed by programmers, for programmers. Therefore the opinions of ordinary computer users had never factored into the design of file system commands, so the distinction does not exist there.

  • 1
    That's annoying. So the answer is yes, no and maybe. OK, at least I can say 'assuming you're not wired up to any events then the statement holds true'. – BanksySan May 6 '15 at 18:46
  • Do you have some real-world problem you need to solve where this distinction is relevant? – Robert Harvey May 6 '15 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.