From: Chad Perrin Date: 2012-07-04T08:35:38+09:00 Subject: Re: Copying Files On Wed, Jul 04, 2012 at 03:08:35AM +0900, Alex C. wrote: > Hi, > > I'm very new to this, but here goes. I need to copy files from one place > to another, which sounds simple enough, but there a slight catch. They > are each within their own folder (e.g. C:\folder\folder1\1.txt, > C:\folder\folder2\2.txt) and I want to copy all of these files into a > single folder so they are all grouped together MS Windows does directory expansion at the command line -- right? You could do the work at the command line, then. Given a program that takes the names of the files you want to move, you could do something like this: program_name *\*.txt -d C:\new\ Use OptionParser to deal with the -d option, then just loop through ARGV to move each file. For some example code doing stuff like this, you can have a look at a simple little utility I wrote to change the encodings of filenames: https://bitbucket.org/apotheon/charsetmove If you go to the Source tab on that page, you can browse through the files. The relevant code is in two files: lib/charset_move.rb and bin/cmv. Actually, you can probably ignore the code in charset_move.rb and just look at the cmv file, which contains all the stuff dealing with option handling and looping through non-option command line arguments. The only thing in charset_move that immediately strikes me as relevant to your situation is the FileUtils.mv method. I hope this helps. I tried to give you enough information to make it easy to figure the stuff out without just handing you a complete answer so that what you learn about how to solve problems like this in Ruby will stick better in your brain. -- Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]