move a file

Discussion in 'Ruby' started by Derek Smith, Aug 13, 2009.

  1. Derek Smith

    Derek Smith Guest

    I looked around here and could not find a similar example. please help.
    My goal is to mv a file like so: mv /tmp/dev.log /usr/local/dev.log.tst
    using Ruby 1.8.7

    ruby /tmp/test
    /tmp/test:8: syntax error, unexpected ')', expecting kDO_BLOCK

    derek@derek-laptop:/tmp$ cat /tmp/test
    #!/usr/bin/env ruby -w
    require 'ftools';
    require 'fileutils';

    file="dev.log"
    FileUtils.cp("#{file}", "#{file}.copied")
    ZIPDIR = "/usr/local/"
    FileUtils.mv("#{file}.copied",ZIPDIR"#{file}.tst")
    --
    Posted via http://www.ruby-forum.com/.
    Derek Smith, Aug 13, 2009
    #1
    1. Advertising

  2. Hi,

    Am Donnerstag, 13. Aug 2009, 10:48:10 +0900 schrieb Derek Smith:
    >
    > ruby /tmp/test
    > /tmp/test:8: syntax error, unexpected ')', expecting kDO_BLOCK
    >
    > FileUtils.mv("#{file}.copied",ZIPDIR"#{file}.tst")

    ^^^

    Try it with something like (untested)

    "#{ZIPDIR}/#{file}.tst"
    File.join ZIPDIR, "#{file}.tst"

    Syntax errors are the easiest to solve.

    Bertram


    --
    Bertram Scharpf
    Stuttgart, Deutschland/Germany
    http://www.bertram-scharpf.de
    Bertram Scharpf, Aug 13, 2009
    #2
    1. Advertising

  3. Derek Smith

    7stud -- Guest

    Bertram Scharpf wrote:
    > Hi,
    >
    > Am Donnerstag, 13. Aug 2009, 10:48:10 +0900 schrieb Derek Smith:
    >>
    >> ruby /tmp/test
    >> /tmp/test:8: syntax error, unexpected ')', expecting kDO_BLOCK
    >>
    >> FileUtils.mv("#{file}.copied",ZIPDIR"#{file}.tst")

    > ^^^
    >
    > Try it with something like (untested)
    >
    > "#{ZIPDIR}/#{file}.tst"
    > File.join ZIPDIR, "#{file}.tst"
    >
    > Syntax errors are the easiest to solve.
    >
    > Bertram


    So in this line:

    ZIPDIR"#{file}.tst"

    you determined that you needed to use string interpolation for the
    variable file, but because ZIPDIR is capitalized, you didn't think
    string interpolation was necessary for that variable, and instead you
    just wrote the variable next to the string?
    --
    Posted via http://www.ruby-forum.com/.
    7stud --, Aug 13, 2009
    #3
  4. Derek Smith

    Derek Smith Guest

    7stud -- wrote:
    > Bertram Scharpf wrote:
    >> Hi,
    >>
    >> Am Donnerstag, 13. Aug 2009, 10:48:10 +0900 schrieb Derek Smith:
    >>>
    >>> ruby /tmp/test
    >>> /tmp/test:8: syntax error, unexpected ')', expecting kDO_BLOCK
    >>>
    >>> FileUtils.mv("#{file}.copied",ZIPDIR"#{file}.tst")

    >> ^^^
    >>
    >> Try it with something like (untested)
    >>
    >> "#{ZIPDIR}/#{file}.tst"
    >> File.join ZIPDIR, "#{file}.tst"
    >>
    >> Syntax errors are the easiest to solve.
    >>
    >> Bertram

    >
    > So in this line:
    >
    > ZIPDIR"#{file}.tst"
    >
    > you determined that you needed to use string interpolation for the
    > variable file, but because ZIPDIR is capitalized, you didn't think
    > string interpolation was necessary for that variable, and instead you
    > just wrote the variable next to the string?



    This was what did it!
    Thank you Sir!


    file="dev.log"
    FileUtils.cp("#{file}", "#{file}.copied")
    ZIPDIR = "/usr/local/"
    FileUtils.mv("#{file}.copied","#{ZIPDIR}#{file}.ts
    --
    Posted via http://www.ruby-forum.com/.
    Derek Smith, Aug 14, 2009
    #4
  5. Hi,

    Am Freitag, 14. Aug 2009, 08:46:49 +0900 schrieb Derek Smith:
    > 7stud -- wrote:
    > > Bertram Scharpf wrote:
    > >> Am Donnerstag, 13. Aug 2009, 10:48:10 +0900 schrieb Derek Smith:
    > >>>
    > >>> FileUtils.mv("#{file}.copied",ZIPDIR"#{file}.tst")
    > >>
    > >> Try it with something like (untested)
    > >>
    > >> "#{ZIPDIR}/#{file}.tst"
    > >> File.join ZIPDIR, "#{file}.tst"
    > >>
    > >> Syntax errors are the easiest to solve.

    > >
    > > ZIPDIR"#{file}.tst"
    > >
    > > you determined that you needed to use string interpolation for the
    > > variable file, but because ZIPDIR is capitalized, you didn't think
    > > string interpolation was necessary for that variable, and instead you
    > > just wrote the variable next to the string?

    >
    > This was what did it!
    > Thank you Sir!
    >
    > FileUtils.mv("#{file}.copied","#{ZIPDIR}#{file}.ts


    I think another slash won't hurt in case you occur to forget it.

    FileUtils.mv("#{file}.copied","#{ZIPDIR}/#{file}.tst"
    ^^^

    Bertram


    --
    Bertram Scharpf
    Stuttgart, Deutschland/Germany
    http://www.bertram-scharpf.de
    Bertram Scharpf, Aug 14, 2009
    #5
    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. Replies:
    1
    Views:
    1,033
    zdrakec
    Jul 15, 2005
  2. Tintin92
    Replies:
    1
    Views:
    1,703
    Andrew Thompson
    Feb 14, 2007
  3. MBALOVER
    Replies:
    9
    Views:
    2,292
    Richard Bos
    Mar 17, 2010
  4. Eduardo78
    Replies:
    0
    Views:
    248
    Eduardo78
    Nov 3, 2005
  5. Andrew Tomazos
    Replies:
    2
    Views:
    614
    Nobody
    Dec 12, 2011
Loading...

Share This Page