Re: ruby rookie needs help with mtime method of File
"Carlo E. Prelz" <[email protected]> Thu, 22 Aug 2019 21:04:41 +0200
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <[email protected]> |
Subject: ruby rookie needs help with mtime method of File Date: gio 22 ago 19 01:53:31 -0600 Quoting Barry Kimelman ([email protected]): > I was looking at an example of the "mtime" method for a file and when I > ran the example I received the following traceback > C:\barry\ruby>ruby dir3-glob.rb > backtick1.rb > Traceback (most recent call last): > 2: from dir3-glob.rb:3:in `<main>' > 1: from dir3-glob.rb:3:in `glob' > dir3-glob.rb:6:in `block in <main>': undefined method `mtime' for > "backtick1.rb":String (NoMethodError) > The source of my script is as follows > 1 #!C:\Ruby\bin\ruby.exe -w > 2 > 3 Dir.glob("*.rb") {|file| > 4 # do something with the file here > 5 puts file > 6 mtime = file.mtime > 7 new_filename = "#{mtime.year}-#{mtime.month}-#{mtime.day}.wma" > 8 puts "Renaming #{filename} to #{new_filename} ..." > 9 } > What have I done wrong? mtime is a method of File, not of String Do mtime=File::mtime(file) instead of mtime = file.mtime (then, variable 'filename' on line 8 does not exist, but that's another bug) Carlo -- * Se la Strada e la sua Virtu' non fossero state messe da parte, * K * Carlo E. Prelz - [email protected] che bisogno ci sarebbe * di parlare tanto di amore e di rettitudine? (Chuang-Tzu) Unsubscribe: <mailto:[email protected]?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>