A series of extra constants for the Dir class that define special folders on MS Windows systems, as well as methods for creating and detecting junctions, i.e. symlinks for directories.
gem install win32-dir
require 'win32/dir'
# C:\WINNT or C:\WINDOWS
puts Dir::WINDOWS
# C:\Documents and Settings\Daniel\Start Menu\Programs\Administrative Tools
puts Dir::ADMINTOOLS
Dir.mkdir('C:\from')
Dir.create_junction('C:\to', 'C:\from')
Not all of these are guaranteed to be defined on your system. Also note that the directories are merely defined. It doesn't necessarily mean they actually exist.
The file system directory that is used to store administrative tools for an individual user. The Microsoft Management Console (MMC) will save customized consoles to this directory, and it will roam with the user.
The file system directory containing administrative tools for all users of the computer.
The file system directory that serves as a common repository for application-specific data. A typical path is C:\Documents and Settings\
\Application Data.
This CSIDL is supported by the redistributable shfolder.dll for systems that do not have the Microsoft Internet Explorer 4.0 integrated Shell installed.
The file system directory containing application data for all users. A typical path is C:\Documents and Settings\All Users\Application Data.
The file system directory that contains documents that are common to all users. A typical paths is C:\Documents and Settings\All Users\Documents.
The file system directory that serves as a common repository for Internet cookies. A typical path is C:\Documents and Settings\
\Cookies.
The file system directory that serves as a common repository for Internet history items.
The file system directory that serves as a common repository for temporary Internet files. A typical path is C:\Documents and Settings\
\Local Settings\Temporary Internet Files.
The file system directory that serves as a data repository for local (nonroaming) applications. A typical path is C:\Documents and Settings\
\Local Settings\Application Data.
The file system directory that serves as a common repository for image files. A typical path is C:\Documents and Settings\
\My Documents\My Pictures.
The virtual folder representing the My Documents desktop item. This is equivalent to Dir::MYDOCUMENTS.
The Program Files folder. A typical path is C:\Program Files.
A folder for components that are shared across applications. A typical path is C:\Program Files\Common.
The Windows System folder. A typical path is C:\Windows\System32.
The Windows directory or SYSROOT. This corresponds to the %windir% or %SYSTEMROOT% environment variables. A typical path is C:\Windows.
The file system directory that corresponds to the user's nonlocalized Startup program group.
The virtual folder containing the objects in the user's Recycle Bin.
The file system directory acting as a staging area for files waiting to be written to CD.
The file system directory that corresponds to the nonlocalized Startup program group for all users.
The file system directory that contains files and folders that appear on the desktop for all users. A typical path is C:\Documents and Settings\All Users\Desktop.
The file system directory that serves as a common repository for favorite items common to all users.
The file system directory that serves as a repository for music files common to all users.
The file system directory that serves as a repository for image files common to all users.
The file system directory that contains the directories for the common program groups that appear on the Start menu for all users.
The file system directory that contains the programs and folders that appear on the Start menu for all users.
The file system directory that contains the programs that appear in the Startup folder for all users.
The file system directory that contains the templates that are available to all users.
The file system directory that serves as a repository for video files common to all users.
The virtual folder containing icons for the Control Panel applications.
The virtual folder representing the Windows desktop, the root of the namespace.
The file system directory used to physically store file objects on the desktop (not to be confused with the desktop folder itself).
The virtual folder representing My Computer, containing everything on the local computer: storage devices, printers, and Control Panel. The folder may also contain mapped network drives.
The file system directory that serves as a common repository for the user's favorite items.
A virtual folder containing fonts.
A virtual folder representing the Internet.
The virtual folder representing the My Documents desktop item. See also Dir::PERSONAL.
The file system directory that serves as a common repository for music files.
The file system directory that serves as a common repository for video files.
A file system directory containing the link objects that may exist in the My Network Places virtual folder. It is not the same as Dir::NETWORK, which represents the network namespace root.
A virtual folder representing Network Neighborhood, the root of the network namespace hierarchy.
The virtual folder containing installed printers.
The file system directory that contains the link objects that can exist in the "Printers" virtual folder.
The user's profile folder.
The file system directory containing user profile folders.
The file system directory that contains the user's program groups (which are themselves file system directories).
The file system directory that contains shortcuts to the user's most recently used documents.
The file system directory that contains Send To menu items.
The file system directory containing Start menu items.
The file system directory that corresponds to the user's Startup program group.
The file system directory that serves as a common repository for document templates.
The SHGetFolderPath() documentation on MSDN is somewhat vague about which CSIDL constants are guaranteed to be defined. However, there are 15 which should be defined (see docs above). The rest I cannot vouch for.
Some of these folders are virtual, and the value will be the display name only instead of an actual path.
The Dir.create_junction and Dir.read_junction methods do not work with JRuby.
Please log any bug reports on the project page at http://www.github.com/chef/win32-dir
Suggestions welcome.
Shashank Date and Zach Dennis for the suggestion and supporting comments on the mailing list.
Timothy Byrd and Autrijus Tang for help (directly or indirectly) with the junction methods. Timothy provided a pure Ruby version of the junction code that I later borrowed from.
Most of the documentation was copied from the MSDN web site.
Artistic 2.0
(C) 2003-2015 Daniel J. Berger, All Rights Reserved
This package is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose.
- Daniel J. Berger
- Park Heesob