From: Brian Candler Date: 2007-03-07T01:19:16+09:00 Subject: Re: Attributing an old time stamp for a new file. On Wed, Mar 07, 2007 at 12:34:51AM +0900, Peter Bailey wrote: > unknown wrote: > > On Tue, 6 Mar 2007, Peter Bailey wrote: > > > >> Hello, > >> I need to read some data from some older files and put that info. into > >> simple ASCII text files. But, I want those new text files to have the > >> same time stamp as the original files that the data came from. Is there > >> any way to do that? > >> > >> Thanks, > >> Peter > > > > harp: ~> ri FileUtils.touch > > -------------------------------------------------------- FileUtils#touch > > touch(list, options = {}) > > ------------------------------------------------------------------------ > > Options: noop verbose > > > > Updates modification time (mtime) and access time (atime) of > > file(s) in +list+. Files are created if they don't exist. > > > > FileUtils.touch 'timestamp' > > FileUtils.touch Dir.glob('*.c'); system 'make' > > > > > > -a > > Thanks. ri verbage is rarely clear to me. These sample lines definitely > seem to be referring to Unix stuff. Not really. The first creates an empty file called 'timestamp'; the second updates the timestamps of all files *.c in the current directory, and then runs 'make' (which could be a DOS command) > "make" means nothing in Windows. > where I am. Thanks, anyway. Use the source :-) Find fileutils.rb on your system (on mine it's /usr/lib/ruby/1.8/fileutils.rb but it'll be different under Windows) Scan down to "def touch". You'll see it's a simple function which just calls File.utime(t, t, path) which I think is what you're really looking for. ------------------------------------------------------------ File::utime File.utime(atime, mtime, file_name,...) => integer ------------------------------------------------------------------------ Sets the access and modification times of each named file to the first two arguments. Returns the number of file names in the argument list.