Thanks all, I figure it out, It tried to copy the folder itself to
itself which cause a conflict.

Robert,

How can I SKIP the "." and ".."?
Do you have an Idea?

Thank you all for your answers!

Robert Klemme wrote in post #979115:
> On Wed, Feb 2, 2011 at 1:46 PM, Eliran Bz <eliranbz / gmail.com> wrote:
>> Here is my code:
>>  puts 'Folder could not be created - Already exist'
>>
>> Dir.foreach(srcPath) {
>> |x| theFiles << x
>
> You need do prepend the path, e.g.
>
> theFiles << File.join(srcPath, x)
>
> Also, you need to know that "." and ".." are included in the list of
> entries found.
>
>> puts x
>> }
>>
>> puts 'Files has been inserted to Array'
>>
>> #Make a copy on each file value in the array
>>
>> theFiles.each do |y|
>> FileUtils.cp_r y, destPath + y
>> end
>
> cp_r ("r" means recursive) only really makes sense for directories.
>
>> bin
>> README.rdoc
>>    from C:/Ruby192/lib/ruby/1.9.1/fileutils.rb:1336:in
>> `fu_each_src_dest'
>>    from C:/Ruby192/lib/ruby/1.9.1/fileutils.rb:432:in `cp_r'
>>    from createFolder.rb:28:in `block in <main>'
>>    from createFolder.rb:26:in `each'
>>    from createFolder.rb:26:in `<main>'
>>
>> Please advice.
>>
>> Thanks!
>
> Why don't you just do
>
> FileUtils.cp_r srcPath, time
>
> ?
>
> Btw, conventionally in Ruby we use CamelCase only for class names
> while for all other names we use names_with_underscores.
>
> Cheers
>
> robert

-- 
Posted via http://www.ruby-forum.com/.