Skip to content
djberg96 edited this page Sep 13, 2010 · 4 revisions

win32-dir

The win32-dir library provides additional constants and methods for the core Dir class that are specific to MS Windows. In addition, some core methods have been redefined to be more Windows friendly.

Constants

When you first load win32-dir a series of constants are dynamically generated. This is a one-time cost. The values for these constants are filesystem paths for various system paths that the operating system defines.

These constants should be preferred over hard coded strings. For example, the system directory on a Windows system might be C:\Windows, C:\Win32 or C:\WinNT. Instead of making an assumption about which directory it might be, use the Dir::WINDOWS constant:

require 'win32/dir'

puts Dir::WINDOWS # => "C:\\Windows"

See the documentation for a list of available constants.

Additional methods

The win32-dir library adds the following singleton methods:

  • Dir.create_junction
    Lets you create a junction (similar to a symlink, but for directories only)
  • Dir.empty?
    Is the directory empty?
  • Dir.junction?
    Is the directory a junction?
  • Dir.reparse_point?
    Alias for Dir.junction?

Redefined Methods

  • Dir.pwd
  • Dir.getwd

This method is nearly identical to the core method. Unlike MRI, however, it returns a normalized path.

require 'win32/dir'

Dir.chdir("C:/Progra~1")
Dir.getwd # => C:\Program Files

Dir.chdir("C:/PROGRAM FILES")
Dir.getwd # => C:\Program Files
Clone this wiki locally