30

I've never had this problem before, but for some reason, I can't rename my folder to packages/.

This is the structure:

root
  -  packages_old/
  -  packages

When I try to rename the folder with Thunar, I get an error message saying that the file already exists. Same with mv:

blender iso $ mv packages_old/ packages/
mv: accessing `packages/': Not a directory

Why am I unable to rename my file and folder to have the same name:

root
  -  packages/
  -  packages

I swear I've done this before.

Blender
  • 1,873
  • 2
  • 18
  • 25
  • 23
    Your memory is probably not as foolproof as you think it is. In the unix platform "everything is a file". You cannot have a file and folder with the same name because directories are just a special kind of file. It's related to the traditional .d extensions on directories in /etc. Suppose you did ls packages or vim packages -- how would the system know if you wanted the directory or the file? – jw013 Oct 11 '11 at 21:53
  • 2
    Could you maybe tell us what OS you're using? Because you cannot have a file and a directory have the same name on most OS I know – rahmu Oct 11 '11 at 21:56
  • 2
    @j013, why have you answered in a comment and not wrote an answer? – andcoz Oct 11 '11 at 21:58
  • @rahmu: Well, what about Windows? – Blender Oct 11 '11 at 22:16
  • 2
    You can't do it on Windows, either. On my Windows 7 machine, trying to do so yields the error: There is already a file with the same name as the folder name you specified. Specify a different name. – Chris Down Oct 11 '11 at 22:19
  • @Blender: And I honestly don't know Windows :P – rahmu Oct 11 '11 at 22:25
  • 6
    In Windows, the default settings is to ignore extensions, so you could have a package directory and a package.txt file in the same folder. From Windows Explorer, it will appear that you have to entries called "package", when in fact, it is just hiding part of the filename of one. – Arcege Oct 12 '11 at 00:48

2 Answers2

42

In Unix, almost everything is a file. A directory is a special type of file that from the user's perspective can "contain" other files.

The error Not a directory occurs because your existing file is not a directory, and since a directory is a type of file, and there cannot be two identically named files in one directory, the operation cannot be performed.

Chris Down
  • 125,559
  • 25
  • 270
  • 266
  • 6
    As for your memory problem, maybe in the past your file and directory had the same name but with different case, like "package" and "Package". File names are case-sensitive, so that would work. – noamtm Oct 16 '11 at 10:30
5

Because if you were able to do such a thing, life would be miserable for programmers like me when I try to iterate files in a directory.

For the following pseudocode:

isDir('/path/to/same_file_and_folder_name')

Should the OS reply true or false?

Anthon
  • 79,293