Hi,

I'm struggling with what should be a fairly simple concept, but I'm
somewhat new at this.  I'm trying to iterate through an array of
folders, change location to each directory, acknowledge the files within
that directory, then move the files to subdirectories that exist if and
when the filename contains the subdirectory name.

So root has:

a/
b/
c/
d/


Then each folder has
abcdef-CatName01-abcdef.xml
ghijkl-CatName02-ghijkl.xml
mnop-Catname03-mnop.xml
CatName01/
CatName02/
CatName03/


And I want to move the files into folders so that if there's a CatName01
file, put it into CatName01 folder.

My method takes in 2 existing arrays, instruments[] and cats[], where
instruments are the folders in the root and cats are the folders in the
instruments folders.

I have this which doesn't quite work.

def ins_file_move(instruments, cats)

instruments.each do |current_dir|
  Dir.chdir(current_dir)
  source = Dir.glob('*.xml')
    cats.each do |dest_cats|
    if source.glob(current_dir)
      Dir.mv("#{source}", "#{cats}/#{source}")
    end
    end
  Dir.chdir("..")
end


end
ins_file_move(instruments, cats)


It looks like I can't glob a glob.  I tried match and scan but it's
still treating current_dir as an array through the 2nd each loop.

Can anyone recommend a way to successfully do this?  Either using my
existing approach or something different?  I'm guessing there's probably
a more eloquent way of iterating through an iteration where both are
variables.

Thanks!

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