From: Rob Biedenharn Date: 2007-03-07T02:10:16+09:00 Subject: Re: Attributing an old time stamp for a new file. On Mar 6, 2007, at 11:43 AM, Peter Bailey wrote: > Brian Candler wrote: >> On Wed, Mar 07, 2007 at 12:34:51AM +0900, Peter Bailey wrote: >>>>> Peter >>>> 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 > > Thanks, Brian! Well, no, "make" is meaningless in DOS or Windows, > believe me. But, I did look into the fileutils.rb file and I do indeed > see what you point out. I'd never have thought to look into one of > these > files. Amazing to me. So, I've tried this and it still doesn't work: > > FileUtils.touch("file1", "file2") > > What does "t" stand for above? it is set to Time.now, but you want to do something like: newfile = "#{oldfile}.txt" File.open(oldfile) do |o| File.open(newfile, 'w') do |n| # while line = o.gets # n << fixup(line) # end end end t = File.mtime(oldfile) File.utime(t,t, newfile) Of course the inner loop is whatever you need it to be. The key here is to just do the part of FileUtils.touch that you need which is the call to File.utime on the new file. Since you just had to create it (and fill it with something), you don't have to create it (the rescue clause in touch). (I hadn't run across the File.utime before, but I should've expected that from Perl's influence.) -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com