Tuesday, December 22, 2009

Breaking up files

I'm doing my year-end photo wrap-up, and I have a directory with all my 2009 photos in it, all 7300 of them. It's a lot to sort through, and Windows stops thumbnailing them after a point, making it nearly impossible. I needed to break them up.

I thought about breaking them up by thousands, but I'd still have a thousand images in each folder. I thought about hundreds, but that seemed like too few. But it would have been way too much work to do anything in between, so I went with hundreds.

The files from my camera are named IMGP####.JPG. My first instinct was to run:

for /L %i in (0,1,99) do md %i && move IMGP%i*.JPG %i

But this wouldn't work, because in the first iteration, with zero, it would run move IMGP0*.JPG 0, which would grab everything from IMGP0000 through IMGP0999, the first thousand files. I did a test with:

for /L %i in (00,01,09) do echo %i

I hoped it would take my leading zero into consideration, but it did not.

I ended up running two separate commands:

for /L %i in (0,1,9) do md 0%i && move IMGP0%i*.JPG 0%i
to take care of the first thousand, followed by
for /L %i in (10,1,99) do md %i && move IMGP%i*.JPG %i

It was great. Took no more than three minutes to process the files, and now I have them in manageable chunks.


So what's going on here?

The FOR /L command runs a variable through a given set of values. The set is in the form (startvalue,step,stopvalue). So to do 2 4 6 8, you'd give it (2,2,8). Got it?

The "do" part simply creates a folder with MD (Make Directory), then moves the matching files into it. The double-ampersand separates the commands.

No comments:

Post a Comment