How to copy a file to a non existing directory ?

Discussion in 'Ruby' started by Martin Martinos, Nov 7, 2006.

  1. Is there a way to copy a file to a directory that does not exist ? If I
    try

    require 'fileutils'

    FileUtils.cp('c:/trash.txt', 'c:/mart/martin.txt')

    I get the following message :

    c:/ruby/lib/ruby/1.8/fileutils.rb:1246:in `initialize': No such file or
    director
    y - c:/mart/martin.txt (Errno::ENOENT)
    from c:/ruby/lib/ruby/1.8/fileutils.rb:1246:in `open'
    from c:/ruby/lib/ruby/1.8/fileutils.rb:1246:in `copy_file'
    from c:/ruby/lib/ruby/1.8/fileutils.rb:1245:in `open'
    from c:/ruby/lib/ruby/1.8/fileutils.rb:1245:in `copy_file'
    from c:/ruby/lib/ruby/1.8/fileutils.rb:459:in `copy_file'
    from c:/ruby/lib/ruby/1.8/fileutils.rb:383:in `cp'
    from c:/ruby/lib/ruby/1.8/fileutils.rb:1379:in
    `fu_each_src_dest'
    from c:/ruby/lib/ruby/1.8/fileutils.rb:1395:in
    `fu_each_src_dest0'
    from c:/ruby/lib/ruby/1.8/fileutils.rb:1377:in
    `fu_each_src_dest'
    from c:/ruby/lib/ruby/1.8/fileutils.rb:382:in `cp'
    from C:/Documents and Settings/mchabot/Desktop/CompileServer/New
    Ruby Pr
    ogram.rb:3

    --
    Posted via http://www.ruby-forum.com/.
     
    Martin Martinos, Nov 7, 2006
    #1
    1. Advertising

  2. Martin Martinos

    Robert Conn Guest

    Hi

    You'll need to create the directory first with

    FileUtils.mkdir('c:/mart')

    Bob


    On 7 Nov 2006, at 22:05, Martin Martinos wrote:

    > Is there a way to copy a file to a directory that does not exist ?
    > If I
    > try
    >
    > require 'fileutils'
    >
    > FileUtils.cp('c:/trash.txt', 'c:/mart/martin.txt')
    >
    > I get the following message :
    >
    > c:/ruby/lib/ruby/1.8/fileutils.rb:1246:in `initialize': No such
    > file or
    > director
    > y - c:/mart/martin.txt (Errno::ENOENT)
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:1246:in `open'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:1246:in `copy_file'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:1245:in `open'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:1245:in `copy_file'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:459:in `copy_file'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:383:in `cp'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:1379:in
    > `fu_each_src_dest'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:1395:in
    > `fu_each_src_dest0'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:1377:in
    > `fu_each_src_dest'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:382:in `cp'
    > from C:/Documents and Settings/mchabot/Desktop/
    > CompileServer/New
    > Ruby Pr
    > ogram.rb:3
    >
    > --
    > Posted via http://www.ruby-forum.com/.
    >
     
    Robert Conn, Nov 7, 2006
    #2
    1. Advertising

  3. On 11/8/06, Martin Martinos <> wrote:
    > Is there a way to copy a file to a directory that does not exist ? If I
    > try
    >
    > require 'fileutils'
    >


    FileUtils.mkdir_p(File.dirname('c:/mart/martin.txt'))

    > FileUtils.cp('c:/trash.txt', 'c:/mart/martin.txt')
    >
    > I get the following message :
    >
    > c:/ruby/lib/ruby/1.8/fileutils.rb:1246:in `initialize': No such file or
    > director
    > y - c:/mart/martin.txt (Errno::ENOENT)
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:1246:in `open'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:1246:in `copy_file'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:1245:in `open'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:1245:in `copy_file'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:459:in `copy_file'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:383:in `cp'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:1379:in
    > `fu_each_src_dest'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:1395:in
    > `fu_each_src_dest0'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:1377:in
    > `fu_each_src_dest'
    > from c:/ruby/lib/ruby/1.8/fileutils.rb:382:in `cp'
    > from C:/Documents and Settings/mchabot/Desktop/CompileServer/New
    > Ruby Pr
    > ogram.rb:3
    >
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >
     
    Michael Fellinger, Nov 7, 2006
    #3
  4. Michael Fellinger wrote:
    > On 11/8/06, Martin Martinos <> wrote:
    >> Is there a way to copy a file to a directory that does not exist ? If I
    >> try
    >>
    >> require 'fileutils'
    >>

    >
    > FileUtils.mkdir_p(File.dirname('c:/mart/martin.txt')


    Thanks for your helps it works fine.

    --
    Posted via http://www.ruby-forum.com/.
     
    Martin Martinos, Nov 7, 2006
    #4
    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. John Blair
    Replies:
    4
    Views:
    1,111
    John Saunders
    Jan 12, 2005
  2. Replies:
    6
    Views:
    30,495
    Diplomat
    Jan 12, 2011
  3. Alex
    Replies:
    2
    Views:
    1,287
  4. Replies:
    26
    Views:
    2,175
    Roland Pibinger
    Sep 1, 2006
  5. nungon
    Replies:
    9
    Views:
    169
Loading...

Share This Page