Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > touch

Reply
Thread Tools

touch

 
 
Bret Pettichord
Guest
Posts: n/a
 
      11-14-2006
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

 
Reply With Quote
 
 
 
 
Philip Hallstrom
Guest
Posts: n/a
 
      11-14-2006
> 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/class...s.html#M001802

 
Reply With Quote
 
 
 
 
Bret Pettichord
Guest
Posts: n/a
 
      11-15-2006

Philip Hallstrom wrote:

> What's wrong with FileUtils.touch() ?
>
> http://corelib.rubyonrails.org/class...s.html#M001802


That looks good. Thanks.

In retrospect, i realize that i should have used fxri first.

Bret

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FileUtils.touch not consistent with system('touch') Han Holl Ruby 4 10-12-2006 05:36 AM
BT Speed Touch 330 & nergear wireless router MR814v2 ramcms Wireless Networking 1 03-12-2006 08:44 PM
Bytecc Backup Star One-Touch Backup External Enclosure @ A True Review Silverstrand Front Page News 0 11-24-2005 04:01 PM
RegexAssembly?_0.dll and Zero-touch deployment Alan Seunarayan ASP .Net 1 06-06-2004 05:34 AM
no touch deployment Mark ASP .Net 5 08-27-2003 03:38 PM



Advertisments