What is the difference between a directory and a folder?

纵饮孤独 提交于 2020-08-20 18:12:46

问题


Most people use the terms "folder" and "directory" interchangeably. From a programmer point of view, is there a difference, and if so, what is it? Does it depend on the OS, or is there a broad, general consensus? This at least suggests that there is a difference.


回答1:


Check "The folder metaphor" section at Wikipedia. It states:

There is a difference between a directory, which is a file system concept, and the graphical user interface metaphor that is used to represent it (a folder). For example, Microsoft Windows uses the concept of special folders to help present the contents of the computer to the user in a fairly consistent way that frees the user from having to deal with absolute directory paths, which can vary between versions of Windows, and between individual installations. ...

If one is referring to a container of documents, the term folder is more appropriate. The term directory refers to the way a structured list of document files and folders is stored on the computer. The distinction can be due to the way a directory is accessed; on Unix systems, /usr/bin/ is usually referred to as a directory when viewed in a command line console, but if accessed through a graphical file manager, users may sometimes call it a folder.




回答2:


A folder is not necessarily a physical directory on a disk. It can be, for example, the printers folder or control panel folder in Windows.

Raymond Chen explains:

Windows 95 introduced Windows Explorer and along with it the term folder. What is the relationship between folders and directories?

Some people believe that Windows 95 renamed directories to folders, but it's actually more than that.

Windows Explorer lets you view folders, which are containers in the shell namespace. Directories are one type of folder, namely, folders which correspond to file system locations. There are other types of folders, such as Control Panel or Network Neighborhood or Printers. These other types of folders represent objects in the shell namespace which do not correspond to files. In common usage, the term virtual folder has been applied to refer to folders which are not directories. In other words, we have this Euler diagram:

(Virtual folders = Folders − Directories)

In general, code which manipulates the shell namespace should operate on folders and items, not directories and files, so as not to tie themselves to a particular storage medium. For example, code which limits itself to files won't be able to navigate into a Zip file, since the contents of a Zip file are exposed in the form of a virtual folder.




回答3:


Quoting Álvaro G. Vicario:

Most of the times they are interchangeable terms. Directory is a classical term used since the early times of file systems while folder is a sort of friendly name which may sound more familiar to Windows users.

The main difference is that a folder is a logical concept that does not necessarily map to a physical directory. A directory is an file system object. A folder is a GUI object. Wikipedia explains it this way:

The name folder, presenting an analogy to the file folder used in offices, and used originally by Apple Lisa, is used in almost all modern operating systems' desktop environments. Folders are often depicted with icons which visually resemble physical file folders.

Strictly speaking, there is a difference between a directory which is a file system concept, and the graphical user interface metaphor that is used to represent it (a folder). For example, Microsoft Windows uses the concept of special folders to help present the contents of the computer to the user in a fairly consistent way that frees the user from having to deal with absolute directory paths, which can vary between versions of Windows, and between individual installations.

If one is referring to a container of documents, the term folder is more appropriate. The term directory refers to the way a structured list of document files and folders is stored on the computer. It is comparable to a telephone directory that contains lists of names, numbers and addresses and does not contain the actual documents themselves.




回答4:


  • Directory is a file system concept. In a GUI the directory is represented as a Folder.
  • Example 1: Unix systems, /usr/bin/ is usually referred to as a directory when viewed in a command line console, but if accessed through a graphical file manager, users may sometimes call it a folder.
  • Example 2: Windows uses both Directory (in commands like mkdir, cd) and Folder (in the GUI).

Directory: The name directory represents an analogy to the telephone directory:

Image of a telephone directory


Folder: The name folder represents an analogy to the file folder used in offices:

Image of office folders


Analogy:

  • A Folder is like a room.
  • A Directory is like a hotel keeper who knows all the rooms.

If you want a specific folder, you use the directory. If you want a specific room you ask the hotel keeper. Source




回答5:


I didn't know the difference between these two words in English before, even in the Windows registry editor I could found two sub-keys, Folder and Directory, under HKEY_CLASSES_ROOT.

I didn't know the difference until I created some values manually in registry and observed the differences of context menu items. If I create a node under HKEY_CLASSES_ROOT\Folder\shell only, I found that it appears in the context menu of both the virtual folders (aka system directory), like Recycle Bin, and the file system directory, like C:\Windows.

If I create a node under HKEY_CLASSES_ROOT\Directory\shell only, it only appears in the context menu of the file system directory, like C:\Windows, but not a virtual folder. So, like @AntonyW said, in Windows, folders = virtual folders + file system directories.




回答6:


Names of folders displayed in File Explorer (the GUI formerly called Windows Explorer) are not necessarily the same as the directories they represent. Consider a case where you are trying to programmatically open a particular folder, a plain directory on mass storage, not a virtual store. Say this was specified by a user based on the name displayed in File Explorer. This name could have been overridden by information in an alternate data stream (ADS) on the directory, and your program will not be referring to the file by its true pathname.

In two examples I've encountered, my app could not open a pathname specified by the user. One of these examples was related to OneDrive; I don't remember the full circumstances of the other example. Anyway, the display name is stored in the ADS named ms-properties:$DATA.

You can use CMD.EXE to list the ADS using DIR/R. Renaming such folders using the Properties menu item in File Explorer changes the contents of this ADS, and the name displayed to the end user in File Explorer is what he or she typed. But this procedure does not rename the directory.




回答7:


Your link basically describes what is different on a technical basis. Most of the times People use them interchangeably and which they choose is mostly based on what environment they come from.

Unless you are doing development cross-platform for an application that will modify files, you don't need to know the differences. As soon as you are preparing to work with several different file system types, you should know their differences.

Don't expect people to know which term to use when. I think of those terms as interchangable, since the differences are known to too few people.



来源:https://stackoverflow.com/questions/5078676/what-is-the-difference-between-a-directory-and-a-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!