On Wed, Jan 30, 2013 at 10:11 AM, Arup Rakshit <lists / ruby-forum.com> wrote:
> Joel Pearson wrote in post #1094397:
>> Ok, try **/*.*
>
>
> Perfect! Thanks for your help.
>
> C:\>irb
> irb(main):001:0> Dir.chdir('C:/Documents and Settings/rakshiar/My
> Documents/us>
> => 0
> irb(main):002:0> Dir.pwd
> => "C:/Documents and Settings/rakshiar/My Documents/userdata/Ruby"
> irb(main):003:0> Dir.glob('**/*.*')
> => ["Books/Beginning Ruby.pdf", "Books/Russ Olsen Eloquent Ruby.pdf",
> "Books/Tes
> t.txt", "Scripts/downloadv3.rb", "Scripts/FileNamerenaming.rb"]
> irb(main):004:0>


I think you may need/want to test for file-ness (and not directory- or
other-ness) of the files as well.

Personally, I'd go with the Find stdlib:

require 'find'

def find_files(start,&blk)
  Find.find(start) do |path|
    if File.file?(path)
      yield path
    end
  end
end

def gather_files(src,dst)
  raise "#{src} is not a directory" unless File.directory?(src)
  raise "#{dst} is not a directory" unless File.directory?(dst)
  find_files(src) {|s| File.rename(s,File.join(dst,File.basename(s)))}
end

Then call gather_files with your source directory and target
directory; in your example:

gather_files("C:\","D:\document")

should do it.