Change the timestamp of a file in Ruby

Updated . Posted . Visible to the public.

This is somewhat similar to the touch command of Linux:

FileUtils.touch 'example.txt', :mtime => Time.now - 2.hours

If you omit the :mtime the modification timestamp will be set to the current time:

FileUtils.touch 'example.txt'

You may also pass an array of filenames:

FileUtils.touch %w[ foo bar baz ], :mtime => Time.now - 2.hours

Non-existent files will be created.

Arne Hartherz
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2011-06-30 13:23)