If you want to do something with a directory/folder you use System.IO.Directory but if you want to display a dialog for browsing one you use FolderBrowserDialog?
Why is one named Directory and the other Folder?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There actually is a difference between a directory and a folder, and both terms are used correctly here.
A directory is a file system concept. The
System.IO.Directoryclass, along with most of the classes in theSystem.IOnamespace, deals only with the file system, ie. files, directories, and drives. These are sometimes collectively referred to (programmatically or just grammatically) as file system objects, or FSOs.A folder, on the other hand, is an operating system concept. More specifically, it’s a Windows shell concept. It’s a higher-level concept than a directory. The Windows shell doesn’t usually deal directly with file system objects. Instead, everything is abstracted as namespace objects. There are two types of namespace objects: folders, which are containers for other namespace objects, and files, which aren’t. (Note that a “file” in the namespace doesn’t necessarily correlate to a file on disk. It could be a virtual object, like a printer.)
Most namespace objects represent file system objects, but not all of them do. For instance, the Desktop folder is a virtual folder that houses all of the file system objects in
%USERPROFILE%\Desktop%as well as the file system objects in%ALLUSERSPROFILE%\Desktop, and a few non-file-system objects like the Recycle Bin, My Computer, etc.Like Windows Explorer, the
FolderBrowserDialog(which, as Benny almost mentioned, callsSHBrowseForFolder()) presents an abstract view of folders1, not a direct view of the drives and directories of the file system.It should also be noted that the
System.IO.Directoryclass is part of the ECMA-spec base class library (BCL), which is intended to be platform-agnostic. Directories exist on virtually every platform. TheSystem.Windows.Forms.FolderBrowserDialogclass is not part of the BCL. It’s in the Windows-specific .NET framework, so its designers were free to use Windows concepts, such as the folder2.1 On the other hand, the .NET framework doesn’t actually support namespace objects. Although the
SHBrowseForFolder()function can return any namespace folder, theFolderBrowserDialoguses theBIF_RETURNONLYFSDIRSflag to restrict returns to only folders that represent file system directories. You can’t use theFolderBrowserDialogto allow the user to choose the Printers folder or the Control Panel folder. Nonetheless, though, it does browse by folder, even if it will only retrieve the path to a directory.2 Most modern file browsers borrow the metaphor of folders, representing directories graphically with folder icons, but the abstract concept of folders, as presented here, is a Windows concept that isn’t universally present across platforms.