Thursday, January 18, 2007

Platform: Windows XP, 2003, Vista (PowerShell)

If you're not using Windows PowerShell, you should be. Here's a way I figured out how to flatten a path into a single directory. In my case I had lots of pictures in different folders that had unique names, so it was a matter of doing the following:
gci --recurse . *.jpg | cpi -dest 'c:\flat'

gci, or get-child-item, gets all the files in this directory. It follows all subdirectories with the "--recurse" option. I ran this in the current directory, hence the "." and I just wanted all my JPEG pictures.

Then, pipe it out to cpi cmdlet (copy item) with a -dest and your destination path. It worked GREAT. In the past on Windows I've either done this with Cygwin or with other utilities like XXCOPY ($$$). Free is good, and I'm just getting my feet wet in PowerShell now.

Other sites have discussed this as well.