Library › Coding AI › Small business owners

Preview product photo renames without touching files

Practice: Setting limits and rules. About 5 minutes.

About this exercise

Write a Python script (standard library only) that reads mapping.csv and, for each row, prints what the photo in the photos folder would be renamed to, like IMG_1234.jpg -> ck-lav8.jpg (the SKU lowercased plus .jpg). This is a dry run: Bea wants to check the list first, so the script must not rename, move or copy anything. If a photo isn't in the photos folder, print MISSING IMG_1240.jpg instead. One code block, at most 12 lines, then under 25 words outside the code.

Common mistakes when you ask AI for this

  • Not saying it's a dry run. The AI renames the files straight away, so mistakes can't be caught first. Try: Add: "Dry run: only print old -> new, never rename."
  • Not showing the new name. The AI keeps the SKU's capitals, which the shop platform won't match. Try: Add: "New name is the SKU lowercased plus .jpg."
  • Forgetting missing photos. The AI's script crashes or stays quiet when a photo isn't there. Try: Add: "If the photo is missing, print MISSING <name>."
  • Getting a menu of options. The AI likes to offer two or three versions of the script, so you're left to pick and test them yourself. Try: Add: "Give one script only, in one code block, no alternatives."
  • Getting a tutorial. By default the AI explains every part of the code at length, which you then have to scroll past. Try: Add: "After the code, one line under 12 words. Nothing else."

What a strong prompt includes

  • Says it's a dry run
  • Shows the new name
  • Handles missing photos
  • Rules out extra libraries
  • Caps the code length

Practice this now ↑

Related exercises