Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
touch
bpettichord
11/14/2006 11:39:00 PM
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-...
but it did not work.
(It zeroed the file it touched!)
Any suggestions for a better "touch" in Ruby?
Bret
2 Answers
Philip Hallstrom
11/14/2006 11:53:00 PM
0
bpettichord
11/15/2006 12:09:00 AM
0
Philip Hallstrom wrote:
> What's wrong with FileUtils.touch() ?
>
>
http://corelib.rubyonrails.org/classes/FileUtils.ht...
That looks good. Thanks.
In retrospect, i realize that i should have used fxri first.
Bret
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
touch
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password