Working with the OS

Working with the OS#

The Operating System#

This chapter covers practical topic: working with the Operating System. Working with files, file permissions, running the programs and getting the results, dealing with stdin and stdout and so on.

Files on Windows#

All examples are working under Unix-like Operating Systems and most of them should work in Windows as well. Notice that Ruby shows the file path using slash regardless on which OS it is running.

Dir.pwd
#=> "C:/Ruby200/bin"

File.exists?("c:/windows/system32/drivers/etc/hosts")
#=> true

It is good to use the combinations of the methods Dir::pwd and File::join to ensure that your code is not dependent on the OS:

File.join(Dir.pwd, "ruby.exe")
#=> "C:/Ruby200/bin/ruby.exe"