Strange syntax error on rename

Hi,
I'm a total newb and wanted to get my hands dirty with a lil script I could use right now.
I can get the Dir.foreach to print my directory of files separately in irb and the rename of one existing file with it's tag info also. combining the two seems harder to do. Can someone please help me and show me how to make this work together.

···

-----------------------------------------------
#!/usr/bin/ruby
require 'taglib'

Dir.foreach("/home/music/") do |file|

# Load a file
   TagLib::FileRef.open (file.to_s) do |fileref|
   tag = fileref.tag

   tag.title
   tag.artist

   File.rename ( "#{file}","#{tag.title}-#{tag.artist}.mp3")

end # File is automatically closed at block end

------------------------------------------------------------------------------
here is the error dump
./taglibex.rb:15: syntax error, unexpected ',', expecting ')'
   File.rename ( "#{file}","tag.title-#{tag.artist}.mp3")
                           ^
./taglibex.rb:15: syntax error, unexpected ')', expecting keyword_end

of course the error dump needed to contain the "#{tag.title}" :-[
I had copied a previous error dump by mistake from the cmd line

···

On 12/07/2012 05:17 PM, peteV wrote:

  File.rename ( "#{file}","#{tag.title}-#{tag.artist}.mp3")

end # File is automatically closed at block end

------------------------------------------------------------------------------

here is the error dump
./taglibex.rb:15: syntax error, unexpected ',', expecting ')'
  File.rename ( "#{file}","#{tag.title}-#{tag.artist}.mp3")
                          ^
./taglibex.rb:15: syntax error, unexpected ')', expecting keyword_end

There's a space between rename and the parenthesis, which is unexpected.
Usually we just leave the parens off method calls in ruby.

···

Sent from my phone, so excuse the typos.
On Dec 8, 2012 9:30 AM, "peteV" <pete0verse@gmail.com> wrote:

On 12/07/2012 05:17 PM, peteV wrote:

  File.rename ( "#{file}","#{tag.title}-#{tag.**artist}.mp3")

end # File is automatically closed at block end

------------------------------**------------------------------**------------------

here is the error dump
./taglibex.rb:15: syntax error, unexpected ',', expecting ')'
  File.rename ( "#{file}","#{tag.title}-#{tag.**artist}.mp3")
                          ^
./taglibex.rb:15: syntax error, unexpected ')', expecting keyword_end

of course the error dump needed to contain the "#{tag.title}" :-[

I had copied a previous error dump by mistake from the cmd line

I think the error is due to a missing 'end'
you have 2 'do' blocks but only 1 'end'

Note 'file' is a string so no need to '.to_s' nor "#{..}"

···

On Fri, Dec 7, 2012 at 6:28 PM, peteV <pete0verse@gmail.com> wrote:

On 12/07/2012 05:17 PM, peteV wrote:

  File.rename ( "#{file}","#{tag.title}-#{tag.**artist}.mp3")

end # File is automatically closed at block end

------------------------------**------------------------------**------------------

here is the error dump
./taglibex.rb:15: syntax error, unexpected ',', expecting ')'
  File.rename ( "#{file}","#{tag.title}-#{tag.**artist}.mp3")
                          ^
./taglibex.rb:15: syntax error, unexpected ')', expecting keyword_end

of course the error dump needed to contain the "#{tag.title}" :-[

I had copied a previous error dump by mistake from the cmd line

here's how i'd do it: https://gist.github.com/4237869

···

On Fri, Dec 7, 2012 at 7:45 PM, Chris Hulan <chris.hulan@gmail.com> wrote:

I think the error is due to a missing 'end'
you have 2 'do' blocks but only 1 'end'

Note 'file' is a string so no need to '.to_s' nor "#{..}"

On Fri, Dec 7, 2012 at 6:28 PM, peteV <pete0verse@gmail.com> wrote:

On 12/07/2012 05:17 PM, peteV wrote:

  File.rename ( "#{file}","#{tag.title}-#{tag.**artist}.mp3")

end # File is automatically closed at block end

------------------------------**------------------------------**------------------

here is the error dump
./taglibex.rb:15: syntax error, unexpected ',', expecting ')'
  File.rename ( "#{file}","#{tag.title}-#{tag.**artist}.mp3")
                          ^
./taglibex.rb:15: syntax error, unexpected ')', expecting keyword_end

of course the error dump needed to contain the "#{tag.title}" :-[

I had copied a previous error dump by mistake from the cmd line

thanks guys that got me passed the syntax error.

hey Chris, these are the errors I get now using your code solution

TagLib: FileRef::tag() - Called without a valid file.
TagLib: FileRef::audioProperties() - Called without a valid file.

···

On 12/07/2012 07:54 PM, Chris Hulan wrote:

here's how i'd do it: gist:4237869 · GitHub

On Fri, Dec 7, 2012 at 7:45 PM, Chris Hulan <chris.hulan@gmail.com > <mailto:chris.hulan@gmail.com>> wrote:

    I think the error is due to a missing 'end'
    you have 2 'do' blocks but only 1 'end'

    Note 'file' is a string so no need to '.to_s' nor "#{..}"

    On Fri, Dec 7, 2012 at 6:28 PM, peteV <pete0verse@gmail.com > <mailto:pete0verse@gmail.com>> wrote:

        On 12/07/2012 05:17 PM, peteV wrote:

              File.rename ( "#{file}","#{tag.title}-#{tag.artist}.mp3")

            end # File is automatically closed at block end

            ------------------------------------------------------------------------------

            here is the error dump
            ./taglibex.rb:15: syntax error, unexpected ',', expecting ')'
              File.rename ( "#{file}","#{tag.title}-#{tag.artist}.mp3")
                                      ^
            ./taglibex.rb:15: syntax error, unexpected ')', expecting
            keyword_end

        of course the error dump needed to contain the "#{tag.title}" :-[
        I had copied a previous error dump by mistake from the cmd line

is this happening every time?
possibly some non-mp3 files in the dir?

also, Dir.foreach does not give the full path
so may have to append the path,

···

On Fri, Dec 7, 2012 at 8:14 PM, peteV <pete0verse@gmail.com> wrote:

On 12/07/2012 07:54 PM, Chris Hulan wrote:

here's how i'd do it: https://gist.github.com/4237869

On Fri, Dec 7, 2012 at 7:45 PM, Chris Hulan <chris.hulan@gmail.com> wrote:

I think the error is due to a missing 'end'
you have 2 'do' blocks but only 1 'end'

Note 'file' is a string so no need to '.to_s' nor "#{..}"

On Fri, Dec 7, 2012 at 6:28 PM, peteV <pete0verse@gmail.com> wrote:

On 12/07/2012 05:17 PM, peteV wrote:

  File.rename ( "#{file}","#{tag.title}-#{tag.artist}.mp3")

end # File is automatically closed at block end

------------------------------------------------------------------------------

here is the error dump
./taglibex.rb:15: syntax error, unexpected ',', expecting ')'
  File.rename ( "#{file}","#{tag.title}-#{tag.artist}.mp3")
                           ^
./taglibex.rb:15: syntax error, unexpected ')', expecting keyword_end

of course the error dump needed to contain the "#{tag.title}" :-[

I had copied a previous error dump by mistake from the cmd line

thanks guys that got me passed the syntax error.

hey Chris, these are the errors I get now using your code solution

TagLib: FileRef::tag() - Called without a valid file.
TagLib: FileRef::tag() - Called without a valid file.
TagLib: FileRef::audioProperties() - Called without a valid file.

i updated the gist, but i haven't actually run the code :wink:

···

On Fri, Dec 7, 2012 at 8:29 PM, Chris Hulan <chris.hulan@gmail.com> wrote:

is this happening every time?
possibly some non-mp3 files in the dir?

also, Dir.foreach does not give the full path
so may have to append the path,

On Fri, Dec 7, 2012 at 8:14 PM, peteV <pete0verse@gmail.com> wrote:

On 12/07/2012 07:54 PM, Chris Hulan wrote:

here's how i'd do it: https://gist.github.com/4237869

On Fri, Dec 7, 2012 at 7:45 PM, Chris Hulan <chris.hulan@gmail.com>wrote:

I think the error is due to a missing 'end'
you have 2 'do' blocks but only 1 'end'

Note 'file' is a string so no need to '.to_s' nor "#{..}"

On Fri, Dec 7, 2012 at 6:28 PM, peteV <pete0verse@gmail.com> wrote:

On 12/07/2012 05:17 PM, peteV wrote:

  File.rename ( "#{file}","#{tag.title}-#{tag.artist}.mp3")

end # File is automatically closed at block end

------------------------------------------------------------------------------

here is the error dump
./taglibex.rb:15: syntax error, unexpected ',', expecting ')'
  File.rename ( "#{file}","#{tag.title}-#{tag.artist}.mp3")
                           ^
./taglibex.rb:15: syntax error, unexpected ')', expecting keyword_end

of course the error dump needed to contain the "#{tag.title}" :-[

I had copied a previous error dump by mistake from the cmd line

thanks guys that got me passed the syntax error.

hey Chris, these are the errors I get now using your code solution

TagLib: FileRef::tag() - Called without a valid file.
TagLib: FileRef::tag() - Called without a valid file.
TagLib: FileRef::audioProperties() - Called without a valid file.

yeah some m4a files but the tag is read, I tried it with a single file it worked with just the tag code part. so yeah I was looking at appending the full path and tried it but strangely it does not find a valid file.
scratching my head. I think I need to read more about the blocks and iterators.
I'm trying to learn a bit hands on but once in a while one needs to read a bit :slight_smile:

···

On 12/07/2012 08:32 PM, Chris Hulan wrote:

i updated the gist, but i haven't actually run the code :wink:

On Fri, Dec 7, 2012 at 8:29 PM, Chris Hulan <chris.hulan@gmail.com > <mailto:chris.hulan@gmail.com>> wrote:

    is this happening every time?
    possibly some non-mp3 files in the dir?

    also, Dir.foreach does not give the full path
    so may have to append the path,