Tried writing my first Python script to rename photos and it renamed 400 files with no extension
So I finally got past the tutorials and decided to actually build something useful: a little Python script to rename my vacation photos from last summer in San Diego. I had about 400 files sitting in one folder with names like IMG_4457.JPG, and I wanted them to say something like sandiego_001, sandiego_002, and so on. The tutorial I followed said to use os.rename and keep the extension, so I wrote my loop and ran it. Big mistake. I forgot to slice in the file extension, so every file got renamed to sandiego_001, sandiego_002 and so on, with no .JPG on the end. My computer suddenly saw 400 files it couldn't open. I spent about two hours reading forum threads (ironic, I know) before I got them back by adding .JPG to each name with a second script. What I learned: always test on a copy of like 3 files first, and print what your loop is about to do before it does it. Anyone got a good habit for testing file scripts on a dummy folder before you point them at your real stuff?