CHAPTER 15

image

Files and Directories

Continuing from the previous chapter, here we look at Ruby’s ability to deal with files and directories. Within a Ruby application, we may need to open files, amend those files, and write them back to a particular directory, or we may need to open a file, process this file, and move the file into another directory.

To do this we will use the File class, used in the previous chapter, along with the Dir class which is Ruby’s method of interpreting and interacting with directory paths. Many of the methods of this class have names similar to the relevant Linux command.

To start with, we can begin navigating through ...

Get Ruby Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.