Ruby DirectoriesClass Dir has directory streams as objects which represents directories in underlying file system. Directories are handled with Dir class. Creating a DirectoryTo create a directory mkdir command is used. You can give permission to a directory if you want. Syntax: Example: We have created a directory "project" in out system. Checking a Directory exists or notTo check whether a directory exists or not exists? Method is used. Syntax: Example: Output: the correct directory name display true and wrong directory name display false. Current Working DirectoryTo know the current working directory pwd method is used. Syntax: Example: Output: Removing DirectoryTo remove a directory, rmdir, unlink or delete methods are used. They perform same function for a Ruby directory. Syntax: Example: Output: The exists method returns false as this directory is no longer present. Next TopicRuby exceptions |