How to copy a file to a non existing directory?

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:inopen’
from c:/ruby/lib/ruby/1.8/fileutils.rb:1246:in copy_file' from c:/ruby/lib/ruby/1.8/fileutils.rb:1245:inopen’
from c:/ruby/lib/ruby/1.8/fileutils.rb:1245:in copy_file' from c:/ruby/lib/ruby/1.8/fileutils.rb:459:incopy_file’
from c:/ruby/lib/ruby/1.8/fileutils.rb:383:in cp' from c:/ruby/lib/ruby/1.8/fileutils.rb:1379:infu_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:infu_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

Hi

You’ll need to create the directory first with

FileUtils.mkdir(‘c:/mart’)

Bob

On 11/8/06, Martin M. [email protected] 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’))

Michael F. wrote:

On 11/8/06, Martin M. [email protected] 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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs