touch

Discussion in 'Ruby' started by Bret Pettichord, Nov 14, 2006.

  1. I need to "touch" a file from my ruby script. (This is a unix-based
    command that updates the timestamp on a file, creating it, if it
    doesn't already exist.) I'm running on Windows. A collegue found a port
    of "touch" and installed it and called it using "system", but i would
    rather see a solution that requires less installation.

    I am currently using the following code:

    class File
    def self.touch(filename)
    File.open(filename, 'a'){|f| f.puts ' '}
    end
    end

    This implementation is good enough for my present needs (touching an
    xml file), but it has obvious side effects that could be a problem in
    other contexts.

    I did find a touch command in Ruby in the ptools package at
    http://sourceforge.net/projects/ruby-miscutils/ but it did not work.
    (It zeroed the file it touched!)

    Any suggestions for a better "touch" in Ruby?

    Bret
     
    Bret Pettichord, Nov 14, 2006
    #1
    1. Advertising

  2. > I need to "touch" a file from my ruby script. (This is a unix-based
    > command that updates the timestamp on a file, creating it, if it
    > doesn't already exist.) I'm running on Windows. A collegue found a port
    > of "touch" and installed it and called it using "system", but i would
    > rather see a solution that requires less installation.
    >
    > I am currently using the following code:
    >
    > class File
    > def self.touch(filename)
    > File.open(filename, 'a'){|f| f.puts ' '}
    > end
    > end
    >
    > This implementation is good enough for my present needs (touching an
    > xml file), but it has obvious side effects that could be a problem in
    > other contexts.
    >
    > I did find a touch command in Ruby in the ptools package at
    > http://sourceforge.net/projects/ruby-miscutils/ but it did not work.
    > (It zeroed the file it touched!)
    >
    > Any suggestions for a better "touch" in Ruby?


    What's wrong with FileUtils.touch() ?

    http://corelib.rubyonrails.org/classes/FileUtils.html#M001802
     
    Philip Hallstrom, Nov 14, 2006
    #2
    1. Advertising

  3. Bret Pettichord, Nov 15, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark

    no touch deployment

    Mark, Aug 20, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    2,181
    Eric Cadwell
    Aug 27, 2003
  2. Alan Seunarayan

    RegexAssembly?_0.dll and Zero-touch deployment

    Alan Seunarayan, Jun 5, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,199
    Alan Seunarayan
    Jun 6, 2004
  3. Leon Jollans

    no touch deployment of crystal viewer

    Leon Jollans, Aug 28, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    349
    Leon Jollans
    Aug 28, 2003
  4. Bruce W...1

    "No touch deployment" on a web page?

    Bruce W...1, Nov 18, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    340
    Elizabeth Newman [MS]
    Nov 21, 2003
  5. Han Holl
    Replies:
    4
    Views:
    338
    Nobuyoshi Nakada
    Oct 12, 2006
Loading...

Share This Page