Renaming Your Photos

Let’s do something really useful now. A day ago I got an email from someone wanting to know how to rename a bunch of files. A year ago my wife wanted a program to download the pictures from her camera’s memory card and rename them. I’ll show you a modified version of her program.

But first, we ought to talk about a few new methods we’ll be using in this program. The first is the Dir[] method. We’ve seen [] used with arrays before…you did know that was a method, didn’t you? Oh, yeah, it sure is. You say “arr[2]” and I say “arr.[] 2”—it’s all the same.

Anyway, rather than using an array’s [] method, we’re using the object Dir’s [] method. (The Dir is for directory.) And instead of passing in a number, like with arrays, ...

Get Learn to Program, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.