This page contains automated test results for code from O'Reilly's Ruby Cookbook. If this code looks interesting or useful, you might want to buy the whole book.

Checking to See if a File Exists
CodeExpectedActual
filename = 'a_file.txt'
File.file? filename
false false
require 'fileutils'
FileUtils.touch(filename)
File.file? filename
true true
directory_name = 'a_directory'
FileUtils.mkdir(directory_name)
File.file? directory_name
false false
File.exists? directory_name
true true
File.directory? directory_name
true true
File.directory? filename
false false
File.blockdev? '/dev/hda1'
true true
File.chardev? '/dev/tty1'
true true
File.socket? '/var/run/mysqld/mysqld.sock'
true true
system('mkfifo named_pipe')
File.pipe? 'named_pipe'
true true
new_filename = "#{filename}2"
File.symlink(filename, new_filename)
File.symlink? new_filename
true true
File.file? new_filename
true true