Creating an empty file in Ruby: "touch" equivalent?
If you are worried about file handles:
File.open("foo.txt", "w") {}
From the docs:
If the optional code block is given, it will be passed the opened file as an argument, and the File object will automatically be closed when the block terminates.
FileUtils.touch
looks like what it does, and mirrors* the touch
command:
require 'fileutils'
FileUtils.touch('file.txt')
* Unlike touch(1) you can't update mtime or atime alone. It's also missing a few other nice options.