William (Bill) Froelich
3/6/2007 5:12:00 PM
> -----Original Message-----
> 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?
The "t" is the accesstime and modified time you want to set the file to.
The FileUtils.touch sets the time on the specified file(s) to the
current time (and creates the file if it doesn't exist). This works for
me as expected on Windows.
File.utime will set the time to any artibary time value. Assuming
testfile.txt already exists the following works for me on Windows.
a = Time.now - (24*60*60*3) # To get the time three days ago
File.utime(a,a,"testfile.txt") # To set the accessed and modified time
for the file to three days ago
Hope this helps
--Bill